Quantcast
Channel: VMware Communities : Document List - vSphere PowerCLI
Viewing all articles
Browse latest Browse all 379

Getting PID of running Virtual Machines from a list of servers

$
0
0
#Powershell and plink from Putty
#Getting PID of running Virtual Machines from a list of servers
#You shall supply a password for root as a parameter to the script
param($password = $(throw 'You shall supply a password for root'))
#List of servers
$servers = "esx01","esx02","esx03","esx04"
$data = @()
$account="root"
$regexp ='^root +(?<pid>[1234567890]+).*[/]+(?<machine>.*)[.]vmx$'

for ($i=0;$i -lt $servers.Length; $i++) {
$data += new-Object psobject
$data[$i] | add-Member -membertype noteproperty -name server -value $servers[$i]
$t1=$account + "@" + $servers[$i] + ".avisen.dk"
$t2=.\plink -pw $password $t1 "ps auxfw | grep vmkload_app | grep vmx$"
foreach ($f in $t2) {
$f -match $regexp > $null
$data[$i] | add-Member -membertype noteproperty -name $matches.machine -value $matches.pid
}
}
$data

Viewing all articles
Browse latest Browse all 379

Trending Articles



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