Question

I am performing below tasks on remote machine from a local machine:

  • Creating/Deleting/Modifying some directory
  • Copying some folder from local to remote machine
  • Installing some .exe silently with noninteractive option
  • Exectuing some batch files

I want to write a script in PowerShell. Novice to PowerShell. I have done some basic investigation of terms like "PowerShell Remoting" etc.

What are the things I need to look for? Related exmple for this will help, where should I look for those?

Was it helpful?

Solution

Reading from docs on MSDN:

To run a single command on a remote computer, use the ComputerName parameter. To run a series of related commands that share data, use the New-PSSession cmdlet to create a PSSession (a persistent connection) on the remote computer, and then use the Session parameter of Invoke-Command to run the command in the PSSession. To run a command in a disconnected session, use the InDisconnectedSession parameter. To run a command in a background job, use the AsJob parameter.

So basically you should do something like:

$session = New-PSSession    
Invoke-Command -Session $session -FilePath <PathToScript>

OTHER TIPS

There is a good section on PowerShell remoting in the Getting Started with PowerShell 3.0 Virtual Academy class. If you don't want to start there, read the about_Remote help topic, then move on to the other remoting help topics listed at the bottom.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top