Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Friday, September 2, 2016

What Happens Remote, Stays Remote

Ask yourself this question.  Is it better to have one node preform a 1 minute task 10 times or have 10 nodes perform a 1 minute task at the same time?  PowerShell remoting allows you to perform tasks against multiple nodes at once.  A common problem that I find is that IT Pros have a tendency to either not keep remote workloads remote or to try and perform tasks that cannot be completed remotely on remote nodes.  Let’s first take a look at Invoke-Command.

Invoke-Command -ComputerName <# The Remote Client #> -ScriptBlock {
    <# All this executes over there #>
}

Remoting is really not that hard.  You provide Invoke-Command’s –ComputerName parameter with the names of the clients to remote to and everything inside of the –ScriptBlock executes on the remote clients.  Very easy and very cool.  Let’s take a look at a few rules of the road.

  1. The first thing is to do as much as possible on the remote client.  That means put as much code as you can into the –ScriptBlock.  That way you are disrupting someone else’s video gaming experience at work and not your own.  Invoke-Command will reach out to 32 clients at the same time by default.  Take a look at the –ThrottleLimit parameter to adjust this.
  2. The second thing is to return objects.  More accurately, the same kind of object.  This is where having the skill set to create your own custom objects comes into play.  To learn more about the various ways to create an object, take a look at my Advanced Windows PowerShell Scripting training.  You will be interested in the chapter about Advanced Objects
  3. The third thing to remember is that if you need to compare values between different nodes, you must do this from your computer.  These remote sessions do not share information between target nodes so you need to bring that information back to you, make your decision and then act on it.
Enjoy your weekend!


No comments: