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

22 thoughts on “Enabling ESX SSH via PowerCLI

  1. Pingback: Start or stop ESXi services using PowerCLI - vConsultants blog

  2. Pingback: Start or stop ESXi services using PowerCLI - vConsultants blog

  3. Pingback: PowerCLI oneliners - vConsultants blog

  4. JVRAO

    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.

  5. Pingback: 6 ways to enable SSH on an ESXi host | wintelvm

  6. Pingback: List all physical QLogic HBA’s driver and firmware information of all your ESXi 4.1/5.0 hosts using PowerCLI 5.0.1 « Yuri's Technology Blog

  7. Purna

    Can I enable “PermitRootLogin=yes” –> via powercli –> Currently value is “PermitRootLogin=no”
    –> at /etc/ssh/sshd_config

  8. Mike Laverick

    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…

  9. Pingback: Useful Powercli Stuff | VMwise

  10. Carl Chipman

    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…

  11. Pingback: VirtualClouds.info » 6 ways to enable SSH on an ESXi host

  12. Aleksandar

    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

  13. Pingback: Tweets that mention Enabling ESX SSH via PowerCLI | Virtu-Al -- Topsy.com

Leave a Reply to Virtu-Al

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

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