SSH activation oneliner

Still in the Memento/oneliner category, here is one to activate the Remote Tech Support Mode (aka TSM-SSH) on all ESX servers who doesn’t have the right startup policy setted up and/or the service was stopped:

We reconfigure the startup policy to set it up on Start and stop with host (mode = on) and we start the service :

Get-VMHost | ?{ $_.ConnectionState -eq "Connected" } | Get-VMHostService | ?{ $_.Key -eq "TSM-SSH" -and ($_.Policy -ne "on" -or $_.Running -ne $true) } | %{ Set-VMHostService $_ -Policy "on"; Start-VMHostService $_ }