PowerCLI

 View Only
Expand all | Collapse all

Disable SFCB and SLP Services

  • 1.  Disable SFCB and SLP Services

    Posted Feb 08, 2023 11:42 AM

    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



  • 2.  RE: Disable SFCB and SLP Services
    Best Answer

    Posted Feb 08, 2023 12:02 PM

    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
        }

     

     



  • 3.  RE: Disable SFCB and SLP Services

    Posted Feb 08, 2023 01:26 PM

    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



  • 4.  RE: Disable SFCB and SLP Services

    Posted Feb 08, 2023 01:32 PM

    Yes, and the returned output should show that.



  • 5.  RE: Disable SFCB and SLP Services

    Posted Feb 10, 2023 10:48 AM

    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.



  • 6.  RE: Disable SFCB and SLP Services

    Posted Feb 10, 2023 11:01 AM

    Yes, the chkconfig commands will make it persistent across reboots.



  • 7.  RE: Disable SFCB and SLP Services

    Posted Feb 10, 2023 11:07 AM

    Thank You LucD



  • 8.  RE: Disable SFCB and SLP Services

    Posted Feb 14, 2023 08:39 PM

    Hi 

    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. 

     

     



  • 9.  RE: Disable SFCB and SLP Services

    Posted Feb 14, 2023 08:44 PM

    I'm afraid it's hard to see what is going wrong without seeing the code you used.



  • 10.  RE: Disable SFCB and SLP Services

    Posted Feb 15, 2023 04:21 PM

    Hi  

    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"

     

     



  • 11.  RE: Disable SFCB and SLP Services

    Posted Feb 20, 2023 11:38 AM

    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



  • 12.  RE: Disable SFCB and SLP Services

    Posted Feb 20, 2023 11:49 AM

    That looks like your account is missing a privilege on that specific ESXi node.
    Check the Permissions on that ESXi node.



  • 13.  RE: Disable SFCB and SLP Services

    Posted Feb 21, 2023 03:32 AM

     Appreciate your response to my message.