Remote powershell / WinRM to Server 2012
-
I've hit a road block and can't figure out why I am getting this response back. It appears that it connects to the server but it returns: "System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server server2.domain.local failed with the following error message: An invalid argument was supplied". I enabled everything I thought on the remote computer:
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/service @{AllowUnencrypted="true"}
winrm set winrm/config/client @{TrustedHosts="*"}I'm trying to remote powershell so I can run Citrix powershell commands from another computer and here is what I have:
try
{
XenDesktop7 xd = new XenDesktop7("http://server2.domain.local:5985/wsman", @"DOMAIN\Administrator", "#######");
string[] blah = xd.GetCatalogs();foreach (var b in blah) { Console.WriteLine(b); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
public CitrixPowershell(string uri, string username, string password)
{
this._connection = GetConnection(uri, username, password);
PSSnapInException snapinException;
_runspace = RunspaceFactory.CreateRunspace(_connection);
_runspace.Open();\_runspace.RunspaceConfiguration.AddPSSnapIn("Citrix.\*.Admin.V\*", out snapinException); \_powershell = PowerShell.Create(); \_powershell.Runspace = \_runspace; } private WSManConnectionInfo GetConnection(string uri, string username, string password) { SecureString pwd = new SecureString(); foreach (char x in password) pwd.AppendChar(x); PSCredential ps = new PSCredential(username, pwd); WSManConnectionInfo wsinfo = new WSManConnectionInfo(false, "server2.domain.local", 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", ps); wsinfo.AuthenticationMechanism = AuthenticationMechanism.Basic; wsinfo.ProxyAuthentication = AuthenticationMechanism.Negotiate; return wsinfo; }
-
I've hit a road block and can't figure out why I am getting this response back. It appears that it connects to the server but it returns: "System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server server2.domain.local failed with the following error message: An invalid argument was supplied". I enabled everything I thought on the remote computer:
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/service @{AllowUnencrypted="true"}
winrm set winrm/config/client @{TrustedHosts="*"}I'm trying to remote powershell so I can run Citrix powershell commands from another computer and here is what I have:
try
{
XenDesktop7 xd = new XenDesktop7("http://server2.domain.local:5985/wsman", @"DOMAIN\Administrator", "#######");
string[] blah = xd.GetCatalogs();foreach (var b in blah) { Console.WriteLine(b); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
public CitrixPowershell(string uri, string username, string password)
{
this._connection = GetConnection(uri, username, password);
PSSnapInException snapinException;
_runspace = RunspaceFactory.CreateRunspace(_connection);
_runspace.Open();\_runspace.RunspaceConfiguration.AddPSSnapIn("Citrix.\*.Admin.V\*", out snapinException); \_powershell = PowerShell.Create(); \_powershell.Runspace = \_runspace; } private WSManConnectionInfo GetConnection(string uri, string username, string password) { SecureString pwd = new SecureString(); foreach (char x in password) pwd.AppendChar(x); PSCredential ps = new PSCredential(username, pwd); WSManConnectionInfo wsinfo = new WSManConnectionInfo(false, "server2.domain.local", 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", ps); wsinfo.AuthenticationMechanism = AuthenticationMechanism.Basic; wsinfo.ProxyAuthentication = AuthenticationMechanism.Negotiate; return wsinfo; }
-
JD86 wrote:
failed with the following error message: An invalid argument was supplied".
Somewhere in your application there is a line of code that has a bad parameter. Identify that and you are on your way to a solution.
But thats the issue. I've compared it with numerous code examples and this should be working. Example: https://com2kid.wordpress.com/2011/09/22/remotely-executing-commands-in-powershell-using-c/[^] [^] The only thing I can think of is that this is a Server 2012 R2 box and wondering if there is something funky with the security. I haven't tried to a 2008 R2 box yet but plan on doing that today.
-
But thats the issue. I've compared it with numerous code examples and this should be working. Example: https://com2kid.wordpress.com/2011/09/22/remotely-executing-commands-in-powershell-using-c/[^] [^] The only thing I can think of is that this is a Server 2012 R2 box and wondering if there is something funky with the security. I haven't tried to a 2008 R2 box yet but plan on doing that today.
-
JD86 wrote:
this should be working.
Maybe so, but you still need to do some debugging to find out why it isn't.