Search code examples
powershellvirtual-machinevmwarepowercliesxi

enable ssh service on vm deployed inside esxi using powercli


I have few vm's deployed inside an esxi,whose details I can find out using "Get-Vm"

command,now I want to enable ssh for these all vm's ,but unable to do so.I am aware

of command to enable ssh for host/esxi like:

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

But cant figure out a way to enable ssh for the vm's inside a esxi,any pointers will be appreciated.


Solution

  • The command you're referencing is for controlling the ESXi Host's SSH service and has no bearing on the guest VM's SSH status.

    To enable SSH on those guests will require a couple things, namely VMware Tools installed and running as well as some valid credentials to the guest OS.

    Once you have those, you can use the Invoke-VMScript cmdlet to send commands to the VM through VMware Tools.

    Example:

    Invoke-VMScript -VM vmName -ScriptType Bash -ScriptText "systemctl start sshd.service" -GuestUser username -GuestPassword password