Executing script existing only on a remote system using Invoke-Command

by ravikanthchaganti on May 14, 2010
188 Views

This is more of a personal note and may sound trivial to many of you out there. But just wanted to make sure I share it here. A while back, in my remoting series, I wrote about executing commands / scripts on a remote machine using Invoke-Command cmdlet. Talking specifically about scripts, you can use -FilePath parameter to execute scripts on a remote machine.

Invoke-Command -ComputerName SP2010-WFE -FilePath C:\scripts\Test.PS1

Note that the script you provide as a value to -FilePath must exist on the local machine or at a place accessible to the local machine. So, what if you want to run a script that exists only on the remote server? You can use script block for that.

Invoke-Command -ComputerName SP2010-WFE -scriptBlock { C:\scripts\Test.PS1 }

This way, you can execute the script present on a remote machine but not on the local system.

Related Posts

{ 1 trackback }

Leave a Comment

Previous post:

Next post: