Enabling ESX SSH via PowerCLI

Ok, I have been living under a rock a little recently, I have had so much going on that my blog and my hands on time has been suffering, sorry for that.

Whilst delivering a presentation on the new features in vSphere 4.1 – Of which there are tons (should have been 4.5 in my opinion), I came across the ability to be able to enable SSH from the DCUI (Direct Console User Interface).

image

This has also been made available as a service in vCenter now where they can be remotely started and stopped….

image

OK, so this is probably not new news for the people who have had time to play with 4.1 but the cool thing is that that this is now also available via PowerCLI too, we can see this if we retrieve the VMHost and then run a Get-VMHostService on it….

image

This is great news, so now if we needed to we could start the SSH service for each of our hosts with just a simple piece of code:

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

We can also do this for any of the other services in the list including restarting the vCenter Agent – Now that’s a cool new feature in 4.1 !

We can also list all of our hosts and see if the service is running using the following one-liner:

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

21 thoughts on “Enabling ESX SSH via PowerCLI”

  1. Thank you so much for this best simple code. I tried to modify your code to start the service on the single host, but it is in vain. Much appreciated your help Alan.

  2. I couldn’t get this script to work for me on ESXi 5. I think its because the service name has changed? Using “Get-VmHostService -VMHost esx03nj.corp.com” I found out the name of the service is “SSH”…

    Changing the script to:

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

    Worked just fine.

    Thanks Alan…

  3. When I run the command to list all of the states, it gives the following output:

    VMHost Label Running
    —— —– ——-
    Remote Tech Support (SSH) False
    Remote Tech Support (SSH) False
    Remote Tech Support (SSH) True
    Remote Tech Support (SSH) True
    Remote Tech Support (SSH) True
    Remote Tech Support (SSH) True
    Remote Tech Support (SSH) True
    Remote Tech Support (SSH) False

    I’m not sure why it won’t output the name of the host…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.