Hi LucD,
As per the slpd status script earlier on, I wish to now disable both the SFCB and SLP services on all the hosts. In the script I wish to set the hosts not to turn these two services on when rebooted. I am not sure if the below script has this feature or you can cook something up 🙂
Again thanks in advance for your help.
Powercli Options To Disable SFCB and SLP Services - VMware Technology Network VMTN
Many Thanks
That script looks ok, but you can also just adapt the code in the script I provided earlier to include the actions for SFCB.
$cmdsub = @'
/etc/init.d/slpd stop;
/etc/init.d/slpd status;
/etc/init.d/sfcbd-watchdog stop;
/etc/init.d/sfcbd-watchdog status;
chkconfig slpd off;
chkconfig --list | grep slpd;
chkconfig sfcbd-watchdog off;
chkconfig --list | grep sfcbd-watchdog;
'@
$secPswd = ConvertTo-SecureString 'VMware1!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('root', $secPswd)
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
Get-VMHostService -VMHost $esx | where { $_.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 -ExpandProperty Output
Remove-SSHSession -SSHSession $session | Out-Null
Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' } | Stop-VMHostService -Confirm:$false | Out-Null
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That script looks ok, but you can also just adapt the code in the script I provided earlier to include the actions for SFCB.
$cmdsub = @'
/etc/init.d/slpd stop;
/etc/init.d/slpd status;
/etc/init.d/sfcbd-watchdog stop;
/etc/init.d/sfcbd-watchdog status;
chkconfig slpd off;
chkconfig --list | grep slpd;
chkconfig sfcbd-watchdog off;
chkconfig --list | grep sfcbd-watchdog;
'@
$secPswd = ConvertTo-SecureString 'VMware1!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('root', $secPswd)
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
Get-VMHostService -VMHost $esx | where { $_.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 -ExpandProperty Output
Remove-SSHSession -SSHSession $session | Out-Null
Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' } | Stop-VMHostService -Confirm:$false | Out-Null
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thank you for the above, just confirm the above script will turn off the SLPD and SFCB? My environment has both on.
Thanks
Yes, and the returned output should show that.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, worked perfectly....Legend.
Quick question, will the above settings stay as off when a host is rebooted? I haven't test this at the moment. If not please provide the line of code to insert in the above script to keep the values off when rebooted.
Thanks in advance.
Yes, the chkconfig commands will make it persistent across reboots.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank You LucD😉
Hi @LucD
Thanks for the code. Looking for a way to export output of each of these commands as separate column, for each host with first column being the hostname (and possibly include vCenter and Cluster Name).
Tried defining PS Object to capture the output and pass it onto Export-CSV, however looks like the Invoke-SSHCommand output is not compatible with the PS Object. Got the error: "Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named ‘op_Addition’".
I don't have the piece of code handy to share here, Sorry!
Please advise.
I'm afraid it's hard to see what is going wrong without seeing the code you used.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi @LucD
Editing the previous reply.
I was able to fix my issues. Please find the updated code below. In order to export each command's output to csv, had to repeat the code.
Is there a better way, I can pass all the commands in singe line (when I plan to enable $cmdsub block) but still be able to generate one csv with output of each command to separate columns, including the columns for vCenter/Cluster/Hostname.
Import-Module VMware.VimAutomation.Core
Import-Module PoSH-SSH
$vcenter = Read-Host " Enter FQDN Or IP address of the vcenter"
$UserName = Read-Host "Enter vCenter Username"
$VCCred = Get-Credential -UserName $UserName -Message "Please enter Password of SSO Credentials"
$VCConnection = Connect-VIServer -Server $vcenter -Credential $VCCred | Out-Null
$Date = (Get-Date).tostring("dd-MM-yyyy-hh-mm-ss")
$ResultFile = "C:\temp\Output-$vcenter-$Date.csv"
$VMSAServiceStatus = @()
<#$cmdsub = @'
/etc/init.d/slpd stop;
/etc/init.d/slpd status;
/etc/init.d/sfcbd-watchdog stop;
/etc/init.d/sfcbd-watchdog status;
chkconfig slpd off;
chkconfig --list | grep slpd;
chkconfig sfcbd-watchdog off;
chkconfig --list | grep sfcbd-watchdog;
'@#>
$cmd1 = '/etc/init.d/slpd status'
$cmd2 = '/etc/init.d/sfcbd-watchdog status'
$secPswd = ConvertTo-SecureString 'xxxxxxx' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('root', $secPswd)
Get-Cluster -Name "xxxxxxx" | Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$ServiceStatus = @()
$ServiceStatus = new-object PSObject
$ServiceStatus | add-member -type NoteProperty -Name HostName -Value $esx.Name
Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' } | Start-VMHostService -Confirm:$false | Out-Null
$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey
Write-Host "$esx.Name status:"
$slpdServiceState = Invoke-SSHCommand -SSHSession $session -Command $cmd1 | select -ExpandProperty Output
$ServiceStatus | add-member -type NoteProperty -Name slpd_CurrentStatus -Value $slpdServiceState
$sfcbdServiceState = Invoke-SSHCommand -SSHSession $session -Command $cmd2 | select -ExpandProperty Output
$ServiceStatus | add-member -type NoteProperty -Name sfcbd_CurrentStatus -Value $sfcbdServiceState
Remove-SSHSession -SSHSession $session | Out-Null
Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' } | Stop-VMHostService -Confirm:$false | Out-Null
$VMSAServiceStatus += $ServiceStatus
}
$VMSAServiceStatus | export-csv -Path $ResultFile -notype
Write-Host "Please check the final result file - $ResultFile"
Hi LucD,
I have tried to run the above working script on a different environment and get the following error:
Start-VMHostService : 20/02/2023 11:27:05 Start-VMHostService Permission to perform this operation was
denied.
Required privilege 'Host.Config.NetService' on managed object with id 'HostSystem-host-35'.
At C:\temp\mo\slpdfix.ps1:19 char:75
+ ... $_.Key -eq 'TSM-SSH' } | Start-VMHostService -Confirm:$false | Out-N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Start-VMHostService], NoPermission
+ FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_SetVMHostService_ViError,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.StartVMHostService
I haven't changed anything on the script, please let me know how i can fix this error.
Many Thanks
That looks like your account is missing a privilege on that specific ESXi node.
Check the Permissions on that ESXi node.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD Appreciate your response to my message.