36 lines
1.3 KiB
PowerShell
36 lines
1.3 KiB
PowerShell
$jumps = 'rejk-a-tcs201','rejk-a-tcs202','rejk-a-mdl201'
|
|
$target = 'rejk-a-cac201'
|
|
|
|
$targetScript = {
|
|
return "$env:COMPUTERNAME was here"
|
|
}
|
|
|
|
$credentials = Get-Credential
|
|
|
|
$jumpScript = {
|
|
param($jumps, $target, $jumpScript, $targetScript, $credentials)
|
|
|
|
"Hello from $env:COMPUTERNAME - Jumps remaining: $($jumps.Count)"
|
|
|
|
|
|
if($jumps.Count -gt 0) {
|
|
$nextJump = $jumps | select -First 1
|
|
$remainingJumps = @($jumps | select -Skip 1) #v2 fix
|
|
|
|
Invoke-Command -ScriptBlock ([scriptblock]::Create($jumpScript)) -ComputerName $nextJump -Credential $credentials -ArgumentList $remainingJumps, $target, $jumpScript, $targetScript, $credentials
|
|
}
|
|
else {
|
|
Invoke-Command -ScriptBlock ([scriptblock]::Create($targetScript)) -ComputerName $target -Credential $credentials
|
|
}
|
|
}
|
|
|
|
|
|
if($jumps.Count -gt 0) {
|
|
$nextJump = $jumps | select -First 1
|
|
$remainingJumps = @($jumps | select -Skip 1)
|
|
|
|
Invoke-Command -ScriptBlock $jumpScript -ComputerName $nextJump -Credential $credentials -ArgumentList $remainingJumps, $target, $jumpScript, $targetScript, $credentials
|
|
}
|
|
else {
|
|
Invoke-Command -ScriptBlock $targetScript -ComputerName $target -Credential $credentials
|
|
} |