3

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.

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.