PowerShell Remoting Fanout
Fanout is running one command on many computers at once. You write the command once instead of repeating it on each computer.
Targets are names in a list
A target list is an ordinary list of names. Each name stands for one computer you plan to reach.
$targets = @("alpha", "beta", "gamma")
$targets -join ", "One loop sends the command to each target
A loop walks the target list. Each pass sends the same block with that target name.
$targets = @("alpha", "beta", "gamma")
foreach ($t in $targets) {
Invoke-Command -ScriptBlock { param($n) "Hello $n" } -ArgumentList $t
}Results come back together
Collect the results in a variable. Then print a count so you can see every target answered.
$targets = @("alpha", "beta", "gamma")
$results = foreach ($t in $targets) {
Invoke-Command -ScriptBlock { param($n) "Hello $n" } -ArgumentList $t
}
"Targets checked: " + $results.CountExample
$targets = @("alpha", "beta", "gamma")
$results = foreach ($t in $targets) {
Invoke-Command -ScriptBlock { param($n) "Checked $n" } -ArgumentList $t
}
$results -join ", "
"Targets checked: " + $results.CountKey points
- Fanout: one command sent to many targets at once.
- Target: one computer in the list you are sending to.
- Target list: a list of names you plan to send the command to.
- Same command: every target gets the same script block.
- Joined results: results come back from all targets and you read them together.
In this example, a list holds three target names. A loop sends the same block once per target. The results are joined into one line, and a count confirms all three answered.
Note
The targets in this lesson are names in a list only. No remote computer is contacted, and each run happens on this machine.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What is fanout?