PowerCLI

 View Only
Expand all | Collapse all

SLPD service - Show a list of host and if the service is on or off

  • 1.  SLPD service - Show a list of host and if the service is on or off

    Posted Feb 06, 2023 08:38 PM

    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



  • 2.  RE: SLPD service - Show a list of host and if the service is on or off



  • 3.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 07, 2023 08:52 AM

    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.

     



  • 4.  RE: SLPD service - Show a list of host and if the service is on or off
    Best Answer

    Posted Feb 07, 2023 09:15 AM

    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
    }
    

     



  • 5.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 07, 2023 02:21 PM

    AMAZING.....you are a LEGEND...! Worked like a dream



  • 6.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 07, 2023 02:39 PM

    I tested the above script in my lab. There are 3 esxi hosts in my lab and SLPD service stopped for 2 hosts and running on 1 host. However, the output showing SLPD off only.

    I've attached a screenshot for the host where SLPD running. Could you please have a look.



  • 7.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 07, 2023 03:43 PM

    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



  • 8.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 07, 2023 04:24 PM

    Excellent LucD. Both checks (persistent and current status) providing the result now. Appreciate your support.



  • 9.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 08, 2023 11:08 AM
      |   view attached

    Hi Lucd,

    Thanks for reply, But when i run above script..I get error attached.

    Regards,

    Kumar.



  • 10.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 08, 2023 11:14 AM

    Looks like the SSH session (New-SSHSession) was not established.



  • 11.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 08, 2023 11:21 AM

    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



  • 12.  RE: SLPD service - Show a list of host and if the service is on or off

    Posted Feb 08, 2023 11:55 AM

    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'