Ok, I see.
The following will only list the status of the SLPD service on all ESXi nodes.
Note, the code does assume that the root credentials on all ESXi nodes are the same
$user = 'root'
$pswd = 'VMware1!'
$cmdsub = @'
chkconfig --list | grep slpd;
'@
$secPswd = ConvertTo-SecureString -String $pswd -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $secPswd)
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
Get-VMHostService -VMHost $esx | Where-Object { $_.Key -eq 'TSM-SSH' } | Start-VMHostService -Confirm:$false | Out-Null
$session = New-SSHSession -ComputerName $esx.Name -Credential $cred -AcceptKey
Invoke-SSHCommand -SSHSession $session -Command $cmdSub |
Select-Object @{N = 'VMHost'; E = { $esx.Name } }, @{N = 'SLPD'; E = { $_.Output } }
Remove-SSHSession -SSHSession $session | Out-Null
Get-VMHostService -VMHost $esx | Where-Object { $_.Key -eq 'TSM-SSH' } | Stop-VMHostService -Confirm:$false | Out-Null
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference