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
Why would I answer your question?
You never bothered to answer on previous thread when I provided a reply
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry about that, i might be due to some personal reason. If you can, please assist me on this query. Thanks in advance.
Your function calls seem to wrong, that should be
Disable-OpenSLP -VMHost $VMHost
Enable-OpenSLP -VMHost $VMHost
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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:~]
That is because the test in your function makes no sense with Length.
That should be something like this
if ($service -eq $null) {
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
Looks like the service is not running on that ESXi node.
What is in the $service variable?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Forgot to answer the service variable part its "SPL" and at the ESXi firewall it is 'CIM SPL"
I have no clue what you are talking about I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
That is what I just explained, you use the Get-EsxCli cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$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
That is not how Get-EsxCli works, you start with
$esxcli = Get-EsxCcl -VMHost <esxname> -V2
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference