I'm unable to figure out why this script only works when no select property are specified.
This doesn't work
Get-VMHost|Get-VMHostService|where {$_.Key -eq 'TSM-SSH' -and $_.Running} |select vmhost, label, running|ogv -PassThru -title "Select ESX where SSH should be stopped"|Stop-VMHostService -confirm:$false
This works but the view doesn't contain hostnames ![]()
Get-VMHost|Get-VMHostService|where {$_.Key -eq 'TSM-SSH' -and $_.Running} |ogv -PassThru -title "Select ESX where SSH should be stopped"|Stop-VMHostService -confirm:$false
Any help appreciated
Got it, try like this
If you want to display more properties in the first Select, you will have to add calculated properties to that Select.
Get-VMHost | Get-VMHostService |where {$_.Key -eq 'TSM-SSH' -and $_.Running} |
select @{N='ESX';E={$_.VMHost.Name}},@{N='Service';E={$_}} |
Out-GridView -OutputMode Multiple -Title "Select ESX where SSH should be stopped" |
select -ExpandProperty Service |
Stop-VMHostService -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is more of a generic PowerShell question. Instead of select, you could try Format-List or Format-Custom. I have found that when you've got a lot of output that is not standard (i.e. PowerCLI stuff) Format-List will display things nice and cleanly.
The Stop-VMHostService cmdlet expects a HostService object in the pipeline.
Try like this
Get-VMHost | Get-VMHostService |where {$_.Key -eq 'TSM-SSH' -and $_.Running} |
Out-GridView -OutputMode Multiple -Title "Select ESX where SSH should be stopped" |
Stop-VMHostService -confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc
Yes this script works, but no hostname is displayed, so you :
Key Label Policy Running Required
--- ----- ------ ------- --------
TSM-SSH SSH off True False
TSM-SSH SSH off True False
If you select the vmhost the properties are missing from the Hostservice object and the script fail ![]()
Get-VMHost | Get-VMHostService |where {$_.Key -eq 'TSM-SSH' -and $_.Running} | select vmhost |
Out-GridView -OutputMode Multiple -Title "Select ESX where SSH should be stopped" |
Stop-VMHostService -confirm:$false
Got it, try like this
If you want to display more properties in the first Select, you will have to add calculated properties to that Select.
Get-VMHost | Get-VMHostService |where {$_.Key -eq 'TSM-SSH' -and $_.Running} |
select @{N='ESX';E={$_.VMHost.Name}},@{N='Service';E={$_}} |
Out-GridView -OutputMode Multiple -Title "Select ESX where SSH should be stopped" |
select -ExpandProperty Service |
Stop-VMHostService -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I added the select vmhost,running to display the hosts that was reconfigured:
Stop-VmHostService -Confirm:$false | select vmhost,running
