C# RS connecting to specific exchange configuration

Welcome Forums General PowerShell Q&A C# RS connecting to specific exchange configuration

This topic contains 1 reply, has 2 voices, and was last updated by

4 years, 2 months ago.

  • Author
  • #20434

    Points: 0
    Rank: Member


    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.

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

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

    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

    Points: 2
    Rank: Member

    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.

The topic ‘C# RS connecting to specific exchange configuration’ is closed to new replies.