jravnsba1
Contributor
Contributor

Stop SSH not working if select property is specified ?

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 :disappointed_face:

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

Joern Ravnsbaek
Tags (1)
ThatVaasGuy
Contributor
Contributor

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.

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
jravnsba1
Contributor
Contributor

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 :disappointed_face:

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

Joern Ravnsbaek
Reply
0 Kudos
LucD
Leadership
Leadership

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

View solution in original post

jravnsba1
Contributor
Contributor

I added the select vmhost,running to display the hosts that was reconfigured:

Stop-VmHostService -Confirm:$false | select vmhost,running

Joern Ravnsbaek
Reply
0 Kudos