wing122
Contributor
Contributor

SSH authentication to ESXi host in place of connect-viserver authentication

Wrote a small powercli script that connects to ESXi hosts (bypassing vCenter due to requirement) to grab VM names, hostnames, IPs, host serial...etc. to build an inventory list.

Everything's working, but one last hurdle is to not use connect-viserver to get access to the ESXi host.

The ESXi hosts have SSH key authentication enabled and that's the required way to access them.

I have tried to look for ways to do this, but unable to find examples of this.

Wondering if anyone has references to such set up. Thanks.

LucD​ Your expertise is appreciated.

0 Kudos
4 Replies
LucD
Leadership
Leadership

Are you using the Posh-SSH module?
See also Use Posh-SSH instead of PuTTY

The module supports using SSH keys.

New-SSHSession -ComputerName esx -KeyFile .\sshkeys.pem

It will depend in which format you have been given the keyfile.

It must be in Base64


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wing122
Contributor
Contributor

Thanks for the suggestion. LucD

However, I am looking to run powercli cmdlets(get-vm, get-view...etc) after connection via SSH and not esxcli commands.

Is this possible?

Or is there another way to get these information via esxcli?

VM name, OS hostname, powerstate(on and off) and OS IP address?

0 Kudos
LucD
Leadership
Leadership

There are a couple of commands that you can launch at the console, that return some of the information you're after.

vm-support -V

vim-cmd vmsvc/getallvms


But afaik there are none to 'query' the guest OS of the VMs (for OS name & IP addr)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
1LynnEdmiston
Contributor
Contributor

Hi, LucD,

I love all your posts and they have helped me a lot. I recently found a way to grab Linux OS by using Copy-VMGuestFile to copy the /etc/*-release file to a local folder (had to make a local folder for each VM as part of the script). Then I just used standard Powershell to capture the VM name from the folder and Get-Content for the text file(s).

I am now looking into grabbing Windows registry keys for Windows, but OS version/patch version is much more complicated in Windows!

Thanks again for your great posts,

Lynn Edmiston

0 Kudos