私はC#を使用している.NetアプリケーションからPowerShellとの接続を作成しようとしていました。私はセッションを作成しようとすると接続が完了した後、空のコレクションを返します。C#を使用したPowerShellリモートセッションの作成
string shellUri = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
PSCredential remoteCredential = new PSCredential("userID", StringToSecureString("Password"));
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "Ip Address of server", 5985, "/wsman", shellUri, remoteCredential, 1 * 60 * 1000);
runspace = RunspaceFactory.CreateRunspace(connectionInfo);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = runspace;
ps.AddScript(@"$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://servername/poweshell -Credential " + remoteCredential);
//result count returned is 0
var result = ps.Invoke();
ps.Commands.Clear();
ps.AddCommand("Import-PSSession $Session");
ps.Invoke();
}
あなたは何の成果を期待していますか? – PetSerAl