C# RS connecting to specific exchange configuration

This topic contains 1 reply, has 2 voices, and was last updated by  Matt McNabb 3 years, 7 months ago.

  • Author
  • #20434

    Jesper Larsen


    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],

    connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;

    Runspace runspace = RunspaceFactory.CreateRunspace[connectionInfo];

    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

  • #20485

    Matt McNabb

    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.

You must be logged in to reply to this topic.