user3388395
user3388395

Reputation: 1

Using a batch file on a remote computer's powershell scripts

When using a command like

powershell -command "\\%host1%\supportfiles\mypowershellscript"

from my central server to a remote computer, would it be using that powershell on the remote computer or on my own computer when I run it using the batch?

Upvotes: 0

Views: 93

Answers (1)

Keith Hill
Keith Hill

Reputation: 201652

When you execute:

PowerShell -command <path to a script>

The script, whether it is located on the local machine or on a remote machine, will execute locally. If you want to execute some PowerShell script remotely, you need to enable remoting on the remote machine using Enable-PSRemoting -force. Then on the local machine, you have to execute your script as administrator and your account also has to have admin privileges on the remote machine. Inside your script you can execute parts of the script remotely like so:

$session = New-PSSession remoteComputerName
Invoke-Command -Session $session -Scriptblock { ... script to execute on remoteComputerName ...}
...
Remove-PSSession $session

Upvotes: 1

Related Questions