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).
This has also been made available as a service in vCenter now where they can be remotely started and stopped….
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….
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
VMware Session 4: Advanced performance troubleshooting using esxtop VMworld Session: PowerCLI is for Administrators!











[...] This post was mentioned on Twitter by Eric Siebert and Xinity Bot, Xinity Bot. Xinity Bot said: [virtu-al] Enabling ESX SSH via PowerCLI http://bit.ly/i3vnZ0 [...]
Code for starting the SSH service on all of our VM hosts can be simpler:
Get-VMHost | Get-VMHostService | Where { $_.Key -eq “TSM-SSH”} | Start-VMHostService
Aleksandar, yes you are right, that is an easier way to do it
Hi,
Are you able to enable the webAccess service also with the PSCLI?
Not directly i dont think but you can run putty through powercli or other ssh clients.
Any plans to add control of the services to the Community Powerpack?
Good idea, now to find the time
To bad after closing it, current sessions are not killed.
Seems a security issue to me.
[...] Renouf over at virtu-al.net and Arne Fokkema over at ict-freak.nl for pointing me at a great blog post written by Alan Renouf himself. As Alan mentioned in his blog, it is possible to enable ESXi hosts [...]
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…
[...] this idea from Mr. Alan Renouf’s site, and updated it to suit my needs. We updated several ESXi 3.5 machines, and needed a quick and [...]
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…
Thanks Mike, thats good to know.