views:

43

answers:

1

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.

+3  A: 

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).

Keith Hill
Thanks! If I get everything else working, is it possible to activate the local computer as a remote computer from itself (to test if my remote methods are working)?
John
Yeah, run the Enable-PSRemoting command on your local computer and for hostname use `localhost`. BTW if this answers your question, you might want to mark this as the answer (if it doesn't - then don't). That will boost your "acceptance" rate which will encourage folks to answer any future questions you may have.
Keith Hill