Powershell.Invoke doesn't give back result C# for remote runspace

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
<br/>

I am trying to invoke powershell cmdlet in C# to a remote runspace, but after my invoke my result count is 0 and jumps over the foreach. I cant figure out why my results variable doesnt contain anything after the invoke. This doesnt work for "get-StorageGroupCopyStatus"
too, but does work for "Get-process"
What am I doing wrong?
public virtual void Setup(string _uri, string _userName, String _livePass)<br/>
{<br/>
uri = _uri;<br/>
userName = _userName;<br/>
foreach (char c in _livePass.ToCharArray())<br/>
{<br/>
password.AppendChar(c);<br/>
}<br/>
PSCredential psc = new PSCredential(_userName, password);<br/>
WSManConnectionInfo rri = new WSManConnectionInfo(false, uri, 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", psc);<br/>
<br/>
rri.AuthenticationMechanism = AuthenticationMechanism.Default;<br/>
rri.ProxyAuthentication = AuthenticationMechanism.Negotiate;<br/>
remoteRunSpace = RunspaceFactory.CreateRunspace(rri);<br/>
remoteRunSpace.Open();<br/>
powerShell.Runspace = remoteRunSpace;<br/>
}<br/>


public void addExchange_SnapIn()<br/>
{ <br/>
powerShell.AddCommand("Add-PSSnapin");<br/>
powerShell.AddParameter("Name", "Microsoft.Exchange.Management.Powershell.Admin");<br/>
Collection<PSObject> results = powerShell.Invoke();<br/>
<br/>
foreach (PSObject i in results)<br/>
{<br/>
Console.Write(i.Members.ToString());<br/>
}<br/>
<br/>
}<br/>

<br/>

View the full article
 
Back
Top