Running PowerShell command remotely from VB using remote runspaces / WSMAN

Darren Rose 496 Reputation points
2021-01-11T15:27:16.157+00:00

Hi

I am trying to create a powershell remote runspace to another machine

Following examples here converted to VB - https://video2.skills-academy.com/en-us/powershell/scripting/developer/hosting/remote-runspace-samples?view=powershell-7.1

I get error as below on the "remoteRunspacePool.Open()" / "remoteRunspace.Open()" lines

System.Management.Automation.Remoting.PSRemotingTransportException: 'Connecting to remote server localhost failed with the following error message : Access is denied.

What am I missing?

Remoting is enabled on test machine (enable-psremoting) and winrm qc shows all running correctly

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,710 questions
{count} votes

Accepted answer
  1. Darren Rose 496 Reputation points
    2021-01-16T13:17:32.44+00:00

    Solved, the intial samples I looked at were just for localhost and didn't mention how to do remote machine

    After reply above and reading the below article as well I now have it working :)

    https://video2.skills-academy.com/en-us/powershell/scripting/developer/hosting/creating-remote-runspaces?view=powershell-7.1

    example snippet below which worked for me:-

     Dim creds As New PSCredential("username", GetSecurePassword("password"))  
          
        Dim uri As New System.Uri("http://192.168.1.15:5985/WSMAN")  
          
        Dim connectionInfo As New WSManConnectionInfo(uri, "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", creds)  
          
        Using remoteRunspace As Runspace = RunspaceFactory.CreateRunspace(connectionInfo)  
               remoteRunspace.Open()  
                .....  
        End Using  
          
          
        Private Function GetSecurePassword(ByVal password As String) As SecureString  
                Dim securePassword = New SecureString()  
                For Each c In password  
                    securePassword.AppendChar(c)  
                Next c  
          
                Return securePassword  
        End Function  
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.