Hello

I am trying to run a Powershell script in VS2010 on a 64bit 2008 R2 server with Exchange 2007 Tools installed; and failing miserably

The code is:
vb.net Code:
  1. Dim res As String
  2.     Dim runspace As Runspace = RunspaceFactory.CreateRunspace()
  3.     runspace.Open()
  4.     Using pipeline As Pipeline = runspace.CreatePipeline()
  5.     Dim myScript As String
  6.     myScript = vbCr & vbLf & "set-executionpolicy -scope CurrentUser -executionPolicy RemoteSigned -force" & vbCr & vbLf & _
  7.     "add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin" & vbCr & vbLf & _
  8.     "Get-Mailbox -DomainController Myserver.mydomain.com stest1"
  9.     Dim command As New Command(myScript, True)
  10.  
  11.     pipeline.Commands.Add(command)
  12.  
  13.     Dim results As Collection(Of PSObject) = pipeline.Invoke()
  14.  
  15.     Dim i
  16.     For Each i In results
  17.     res = res & vbCrLf & i
  18.     Next
  19.  
  20.     End Using
  21.     cmdOutputTextBox.Text = res
It fails at "PipeLine.Invoke" with:
The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program.

The code works everywhere except where it's needed

I've tried a few permutations and getting nowhere, can anyone help?

Thanks

Stuart