Verify root password on a group of hosts

I recently received several existing ESX hosts to support. As part of the transition I received the root password used by all of the hosts. I wanted to verify that the password I had was correct, so I threw together a quick script. You may notice below that the password had a dollar sign in it, which as you may know is a special character in powershell so it needed to be escaped with a back tick.

[cc lang=”powershell”]
$esxHosts = “esxi01.test.local”,”esxi02.test.local”
$esxHosts += “esxi03.test.local”,”esx04.test.local”
$esxHosts += “esx05.test.local”,”esxi06.test.local”

$esxHosts |%{
$hostName = $_
$connection = Connect-Viserver $_ -user root -password “pa`$`$w0rd” -ea:0
New-Object PSObject -Property @{
Name=$hostName
IsConnected=$connection.IsConnected
VMCount = (Get-VM).Count
}#end psobject
Disconnect-viserver * -confirm:$false
}#end host loop
[/cc]

This entry was posted in Scripting, Virtualization. Bookmark the permalink.

Leave a Reply

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

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.