Reputation: 97
This might be really obvious, since I'm kind of new to Powershell, but what's the best way to run a Powershell script on one computer that accesses another to run a Powershell script on that one? I'm using V2.0 if that matters.
Upvotes: 3
Views: 2579
Reputation: 201662
First you will need to enable remoting computer on the remote computer. Log onto that computer and from an elevated (admin) prompt execute:
Enable-PSRemoting -Force
Then you can use Invoke-Command to run commands on the remote computer. In the case of a script, you probably want to create a new pssession (New-PSSession) to the remote computer and then invoke commands using that session as a parameter to Invoke-Command e.g.:
$s = new-PSSession -computername (import-csv servers.csv) `
-credential domain01\admin01 -throttlelimit 16
invoke-command -session $s -scriptblock {get-process powershell} -AsJob
Note that you will need to run in an elevated (admin) prompt to be able to use the remoting infrastructure. Look at the help on these two cmdlets for more details as well as the about_remote topic (man about_remote
).
Upvotes: 6