0

I've written a function to interact with the Exchange Shell remotly. Now I want to use it for the normal Windows PS. So I changed the Shell Uri in WSManConnectionInfo to http://schemas.microsoft.com/powershell/Microsoft.PowerShell.

The function looks now like this:

Public Function remotePowerShell(ByVal script as String)

    Dim newCred As PSCredential = DirectCast(Nothing, PSCredential)
    Dim connectionInfo As New WSManConnectionInfo(New Uri("http://SVR2012R2-File/powershell?serializationLevel=Full"), "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", newCred)
    Dim runspace As Runspace = RunspaceFactory.CreateRunspace(connectionInfo)
    connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default
    Dim powershell As PowerShell = powershell.Create()

    Dim command As New PSCommand()

    command.AddScript(script)
    powershell.Commands = command

    Try

        runspace.Open()
        powershell.Runspace = runspace
        Dim psresult As New System.Collections.ObjectModel.Collection(Of PSObject)
        psresult = powershell.Invoke()
        For Each i In psresult
            MsgBox(vbNewLine & i.ToString)
        Next i

    Catch ex As Exception

        MsgBox(Err.Number & vbNewLine & ex.Message)

    Finally

        runspace.Dispose()
        runspace = Nothing

        powershell.Dispose()
        powershell = Nothing

    End Try

End Function

If I run this function now I get the error:

The WS-Management service cannot process the request. The resource URI (http://schemas.microsoft.com/powershell/Microsoft.PowerShell) was no found in the WS-Management catalog. The catalog contains the metadata that describes resource, or logical endpoints.

The function looks now pretty much the same like others of the same kind on SO, CodeProject and MSDN. The ShellUri is correct too.

I then tried another form of WSManConnectionInfo

Dim connectionInfo As New WSManConnectionInfo & _
(False, "SVR2012R2-File", 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", newCred)

Sadly this didn't work either.

I turned off both firewalls (from the Client and Memberserver) and restarted all related services I could think of (RPC, IIS, WS-Management) This shouldn't be a problem anyway as the script works for interaction with the Exchange PS.

Is it possible that I need to define something more or do I need other PSCredentials ?

Thanks in advance for any shared thoughts.

GrindelOh
  • 448
  • 1
  • 10
  • 24
  • Http won't work, because the http://servername/powershell website is installed by the exchange setup routine on Exchange Server (2010+). – Martin Mar 10 '16 at 15:55
  • @Martin which other Shell Uri should I use then? According to multiple posts like (https://msdn.microsoft.com/en-us/library/windows/desktop/ee309368(v=vs.85).aspx) it's the correct one. – GrindelOh Mar 11 '16 at 09:24

0 Answers0