I have the following code to connect to the remote powershell and execute script on remote machine :
WSManConnectionInfo connectionInfo =newWSManConnectionInfo(false,"MachineName",5985,"/wsman", shellUri, credential); using (Runspace runspace =RunspaceFactory.CreateRunspace(connectionInfo)){ runspace.Open(); using (PowerShell powershell =PowerShell.Create()){ powershell.Runspace= runspace;String file =@"C:\scripts\createUser.ps1"; powershell.Commands.AddScript(System.IO.File.ReadAllText(file));Collection<PSObject> results = powershell.Invoke();}}
How to execute the script in same way from powershell command prompt?
↧
Similar to connecting to remote computer using WSManagement, how to do it through powershell terminal?
↧