TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Stuart Barnett
NA
1
1.8k
Calling Powershell Exchange cmdlet in VS2010
Sep 23 2011 8:32 AM
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:
Dim res As String
Dim runspace As Runspace = RunspaceFactory.CreateRunspace()
runspace.Open()
Using pipeline As Pipeline = runspace.CreatePipeline()
Dim myScript As String
myScript = vbCr & vbLf & "set-executionpolicy -scope CurrentUser -executionPolicy RemoteSigned -force" & vbCr & vbLf & _
"add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin" & vbCr & vbLf & _
"Get-Mailbox -DomainController Myserver.mydomain.com stest1"
Dim command As New Command(myScript, True)
pipeline.Commands.Add(command)
Dim results As Collection(Of PSObject) = pipeline.Invoke()
Dim i
For Each i In results
res = res & vbCrLf & i
Next
End Using
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
Reply
Answers (
0
)
C# datagridview printing with vertical columns
Crystal Reports