Automation

 View Only
Expand all | Collapse all

Control OpenSLP on ESXi hosts using PowerCLI

  • 1.  Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 16, 2021 03:08 PM
    I was trying to use the code to stop the OpenSPL service in the ESXi servers through vCenter, but i obtained the following error message - can anyone assist me with the error message

    "Disable-OpenSLP : Cannot process argument transformation on parameter 'VMHost'. Cannot convert value "-OpenSLP" to type
    "VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl". Error: "One of the identified items was in an invalid format."
    At C:\Users\admin_gsskamba\Downloads\Servicedisable.ps1:43 char:25
    + Disable-OpenSLP -VMHost $VMHostEnable-OpenSLP -VMHost $VMHost
    + ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Disable-OpenSLP], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Disable-OpenSLP
    ----------------------------------------------------------------------------------------------------------

    Real Code
    -----
    Function Disable-OpenSLP { param([VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl][Parameter(Mandatory=$true)]$VMHost) $service = $VMHost | Get-VMHostService | Where-Object { $_.Key -eq "slpd" } if ($service.length -ne 1) { throw("ERROR: OpenSLP Service not found on host: $VMHost") } $service | Stop-VMHostService -Confirm:$false -ErrorAction:Stop | Out-Null $service | Set-VMHostService -Policy:Off -ErrorAction:Stop | Out-Null $rule = $VMHost | Get-VMHostFirewallException -Name "CIM SLP" if ($rule.length -ne 1) { throw("ERROR: OpenSLP Firewall rule not found on host: $VMHost") } $rule | Set-VMHostFirewallException -Enabled $false -ErrorAction:Stop | Out-Null Write-Host "OpenSLP Service disabled for host: $VMHost" } Function Enable-OpenSLP { param([VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl][Parameter(Mandatory=$true)]$VMHost) $service = $VMHost | Get-VMHostService | Where-Object { $_.Key -eq "slpd" } if ($service.length -ne 1) { throw("ERROR: OpenSLP Service not found on host: $VMHost") } $service | Start-VMHostService -Confirm:$false -ErrorAction:Stop | Out-Null $service | Set-VMHostService -Policy:Automatic -ErrorAction:Stop | Out-Null $rule = $VMHost | Get-VMHostFirewallException -Name "CIM SLP" if ($rule.length -ne 1) { throw("ERROR: OpenSLP Firewall rule not found on host: $VMHost") } $rule | Set-VMHostFirewallException -Enabled $true -ErrorAction:Stop | Out-Null Write-Host "OpenSLP Service enabled for host: $VMHost" } Connect-VIServer <FQDN of vCenter Server> $VMHost = Get-VMHost <name of VMware ESXi host> Disable-OpenSLP -VMHost $VMHostEnable-OpenSLP -VMHost $VMHost Enable-OpenSLP -VMHost $VMHostEnable-OpenSLP -VMHost $VMHost

     Moderator edit by wila: Moved from VMware {code} to VMware PowerCLI discussions



  • 2.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 16, 2021 05:41 PM

    Why would I answer your question?
    You never bothered to answer on previous thread when I provided a reply



  • 3.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 07:41 AM

    Sorry about that, i might be due to some personal reason. If you can, please assist me on this query. Thanks in advance.



  • 4.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 09:37 AM

    Your function calls seem to wrong, that should be



  • 5.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 10:23 AM

    Thanks for replying...

    Now i obtain the following error,

    ERROR: OpenSLP Service not found on host: xxxxxxxx
    At C:\Users\testuser1\Downloads\Disableservice.ps1:25 char:3
    + throw("ERROR: OpenSLP Service not found on host: $VMHost")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (ERROR: OpenSLP ...:String) [], RuntimeException
    + FullyQualifiedErrorId : ERROR: OpenSLP Service not found on host: xxxxxxxx

    When i run the command on the same ESXi server, we obtain the same error
    [root@xxxxxx:~] chkconfig --list | grep slpd
    slpd on
    [root@xxxxxx:~]



  • 6.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 11:03 AM

    That is because the test in your function makes no sense with Length.
    That should be something like this



  • 7.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 11:29 AM

    I changed the script as listed below, but still i see the same error even now, any other suggestion

    Function Disable-OpenSLP {
    param([VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl][Parameter(Mandatory=$true)]$VMHost)
    $service = $VMHost | Get-VMHostService | Where-Object { $_.Key -eq "slpd" }
    if ($service -eq $null) {
    throw("ERROR: OpenSLP Service not found on host: $VMHost")
    }

    $service | Stop-VMHostService -Confirm:$false -ErrorAction:Stop | Out-Null
    $service | Set-VMHostService -Policy:Off -ErrorAction:Stop | Out-Null

    $rule = $VMHost | Get-VMHostFirewallException -Name "CIM SLP"
    if ($service -eq $null) {
    throw("ERROR: OpenSLP Firewall rule not found on host: $VMHost")
    }

    $rule | Set-VMHostFirewallException -Enabled $false -ErrorAction:Stop | Out-Null
    Write-Host "OpenSLP Service disabled for host: $VMHost"

    }

    Connect-VIServer "xxxxxx"
    $VMHost = Get-VMHost "xxxxxxx"

    Disable-OpenSLP -VMHost $VMHost

     

    Error:

    ERROR: OpenSLP Service not found on host: xxxxxx
    At C:\Users\Testuser1\Downloads\Disableservice.ps1:5 char:3
    + throw("ERROR: OpenSLP Service not found on host: $VMHost")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (ERROR: OpenSLP ...flextronics.com:String) [], RuntimeException
    + FullyQualifiedErrorId : ERROR: OpenSLP Service not found on host: xxxxx



  • 8.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 12:59 PM

    Looks like the service is not running on that ESXi node.
    What is in the $service variable?



  • 9.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 02:31 PM

    am planning to stop the service at the ESXi host through the vCenter console, but the service does not seems to be present in the console. Do we have an alternative way to do that using a script. 



  • 10.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 02:48 PM

    I have no clue what you are talking about I'm afraid.



  • 11.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 22, 2021 06:37 AM

    The script is written to connect vCenter and select a ESXi hosts and to stop the SPL service and disable CIM SPL at the firewall. Am unable to view the OpenSLP service that's running in the ESXi server from the vCenter console, but am able to view the disable option for CIM SPL. That's the reason i asked the question is there i a way perform this through another script



  • 12.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 22, 2021 07:01 AM

    You can use the esxcli command as described in KB76372.
    With the Get-EsxCli cmdlet you can execute esxcli commands against an ESXi node.
    See PowerCLI 6.3 R1: Get-ESXCLI Why the V2? for more info on the V2 switch.



  • 13.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 22, 2021 02:29 PM

    I was trying to find a way how do we perform the stuffs in the KB article through the vCenter, so that i can perform the task on multiple ESXi servers



  • 14.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 22, 2021 02:30 PM

    That is what I just explained, you use the Get-EsxCli cmdlet.



  • 15.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 24, 2021 02:25 PM

    $esxcli2 = Get-ESXCLI -VMHost (Get-VMhostservice | Where-object {$_.key -eq "spld"}) -V2

    When i try to modify the script to obtain the status of the service i do obtain the following error

    Get-VMHostService Value cannot be found for the mandatory parameter VMHost

    Can you help me to pass the ESXiCLi command to the script to get the status of the service and then to stop the service and disable it from in firewall, thanks in advance 



  • 16.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 24, 2021 03:20 PM

    That is not how Get-EsxCli works, you start with



  • 17.  RE: Control OpenSLP on ESXi hosts using PowerCLI

    Posted Apr 21, 2021 02:35 PM

    Forgot to answer the service variable part its "SPL"  and at the ESXi firewall it is 'CIM SPL"