Print Friendly

For my first toe dipping into Powershell, I wanted to be able to turn SSH on and off across all my VMware Hosts..

The backgound to this is that we have been making lots of changes to our vSphere clusters, adding new Nimble Storage and Brocade switches. Many of these actions required some SSH access to the server, even if it was just to check a few settings. The manual way using either the C# or Web Client was clunky and involved a number of clicks. So as always I asked Twitter for some advice..

Many thanks to Dave Hocking for actually suggesting that Powershell would do it, he was right. Good man. My search lead me to this page written by Nicholas Gerasimatos and another by Eric Wright – others were there, but these were particularly easy to follow for a fledgling Powershell user.

  • First step was to down load the latest Powershell files from VMware documentation can be found here
  • Once I had these, I installed them on my vCenter server. You need to remember to..
Set-ExecutionPolicy RemoteSigned
  • Once the install is finished, you get two new icons on the desktop (as shown on the right)Powershell-CLI
  • Double click the PowerCLI (the other one is for 32bit installations)
  • Before anything will work, again another commend is required..
Connect-VIServer -server yourservername
  • From there it’s just a matter of copying and pasting the relevant commands, below are the most useful

See Current Status of SSH

Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } |select VMHost, Label, Running

Turn SSH On for ALL Hosts

Get-VMHost | Foreach { Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} ) }

Turn SSH Off for ALL Hosts (This last script asked for confirmation for each Host, but Eric added the extra command at the end. Nice one)

Get-VMHost | Foreach { Stop-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} ) -Confirm:$FALSE}

 

I can’t claim any credit for the command set, I just hope that having all the information in one place makes it easier for the next Nube. This also gives me another set of toys to play with..

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress spam blocked by CleanTalk.