Author Posts

November 7, 2014 at 6:21 am

Hi

Im trying to figure out how to specify a given Configuration when connecting to a remote server. My task is to do some exchange (2013) queries, and from PS i can do a remote command like this and it works perfectly.

[i]Invoke-Command -ConnectionUri https://servername.com/PowerShell -Credential $user -ScriptBlock {Get-Mailbox somename} -ConfigurationName Microsoft.Exchange[/i]

But when trying to access the it thrugh c# it fails:

[i] WSManConnectionInfo connectionInfo = new WSManConnectionInfo[
new Uri[http://servername.com/PowerShell],
"https://schemas.microsoft.com/powershell/Microsoft.Exchange",
credential];

connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;

Runspace runspace = RunspaceFactory.CreateRunspace[connectionInfo];
runspace.Open[];
[/i]

It comes around saying:

Unhandled Exception: System.Management.Automation.Remoting.PSRemotingTransportEx
ception: Connecting to remote server servername.com failed wi
th the following error message : The WinRM service received a HTTP redirect mess
age redirecting the client but the location URL is invalid. For more information
, see the about_Remote_Troubleshooting Help topic.
at MyApi.GetUser(String azIdent)
at MyApi.ConsoleTest.Program.Main(String[] args)

im a bit puzzled... what IS that?
I do not have access to the server-side.

Hope someone can help me out here...

kind regards Jesper

November 10, 2014 at 10:36 am

Hopefully I'm not pointing out the obvious, but in the Uri in the PS command you used https:// while in the C# example you used http://. It's possible the server is not accepting requests on port 80.