- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi LUCD
I am trying to find a script which will show the chkconfig --list | grep slpd for each host in my vcenter. I have 130 hosts and at the moment I can only do this by logging onto each host which is time consuming.
Please help
Thanks
Mo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have a look at Re: PowerCLI - Workaround for OpenSLP security vul... - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you LucD,
I have gone through the above link and the scripts actually carry out the fix. All I want is an output to show a list of all my hosts in the vCenter with the slpd service name and if its on or off. I can only run the chkconfig --list | grep slpd at host level, like to run this on all hosts at once have an output on csv.
I hope that helps and thanks for your help in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
AMAZING.....you are a LEGEND...! Worked like a dream
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Excellent LucD. Both checks (persistent and current status) providing the result now. Appreciate your support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks like the SSH session (New-SSHSession) was not established.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI Lucd,
If i manually enable SSH and run the below script to verify the SLP status, SSH gets disabled. So it's not able open new SSH session
$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
}
Regards,
Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That code disables the SSH service at the end.
But does New-SshSession actually work?
What is returned when you do
New-SSHSession -ComputerName MyEsx -Credential $cred -AcceptKey -Verbose
Does the ESXi firewall allow SSH traffic?
Check with
Get-VMHostFireWallException -VMhost MyEsx -Name 'SSH *'
Is the SSH session timeout set too short?
Check with
Get-AdvancedSetting -Entity MyEsx -Name 'UserVars.ESXiShellTimeOut'
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference