Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Similar to connecting to remote computer using WSManagement, how to do it through powershell terminal?

$
0
0

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?




Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>