Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Using Start-Job to launch multiple SSH sessions and esxtop?

$
0
0

Hello folks,

I am trying to start an esxtop session on multiple esx servers at the same time.

I started trying using Start-Job thinking it would help do it asynchronously.

The script I have below works on one host so far, but need suggestions to repeat it for multiple hosts, thinking by looping through changing the $i each time?

Checking if anyone would have comment?

$i = 1
$seconds = 5
$iterations = 2
$esxtopfile = "esxtop$i_$((Get-Date).ToString('MMddyyy-hhmm')).csv"
$ComputerName = "z420esxi$i.domain.net"

# Start an esxtop session using SSH.net and start an esxtop command - module already loaded.
$sb = {New-SshSession -ComputerName $($args[0]) -KeyFile C:\esxi-key-openssh.key -Username root
       Invoke-SshCommand -ComputerName $($args[0]) -command "esxtop -d $($args[1]) -a -b -n $($args[2]) > /tmp/$($args[3])"     
}
Start-Job  -ScriptBlock $sb -ArgumentList $ComputerName,$seconds,$iterations,$esxtopfile | Wait-Job | Receive-Job


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>