C# RS connecting to specific exchange configuration

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Matt McNabb Matt McNabb 2 years ago.

  • Author
    Posts
  • #20434
    Profile photo of Jesper Larsen
    Jesper Larsen
    Participant

    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

  • #20485
    Profile photo of Matt McNabb
    Matt McNabb
    Participant

    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.