What I think happened is the following.
The chkconfig --list command shows the persistent status of the service.
The /etc/init.d/slpd status shows the current status.
The code should in fact list the 2 options, current status and the persistent config.
Something like this
$user = 'root'
$pswd = 'VMware1!'
$cmdsub1 = @'
/etc/init.d/slpd status;
'@
$cmdsub2 = @'
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
$current = Invoke-SSHCommand -SSHSession $session -Command $cmdSub1
$persistent = Invoke-SSHCommand -SSHSession $session -Command $cmdSub2
New-Object -TypeName PSObject -Property ([ordered]@{
VMHost = $esx.Name
Current = $current.Output[0]
Persistent = $persistent.Output[0]
})
Remove-SSHSession -SSHSession $session | Out-Null
Get-VMHostService -VMHost $esx | Where-Object { $_.Key -eq 'TSM-SSH' } | Stop-VMHostService -Confirm:$false | Out-Null
}
To stop the service and change the persistent setting, the original thread I pointed to does that
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference