Validate Username / Password on ESX(i) Host

A simple script to validate the login credentials against an ESX(i) host. Useful when validating that the credentials are what you think they should be.

Validates credentials by doing a login to the target host via the VI API.
.\Test-VMHostAccountPassword.ps1 -VMHost "host1","host2","host3"
Get prompted for all credential information so it is not on the command line.
"host1","host2","host3" | .\Test-VMHostAccountPassword.ps1
Use pipelining.
    HelpMessage="An array of VM host names.")]
    HelpMessage="The credential used to connect to the host.")]
    # Provide param prompting. This is a workaround for the multiple prompting that
    # happens if this were done in the PARAM block.
    if (!$credential)
        $myCredential = Get-Credential
        $myCredential = $credential
    foreach ($h in $VMHost)
        $connection = Connect-VIServer -Server $h -Credential $myCredential -ErrorAction SilentlyContinue
        $success = $false
        if ($connection)
            $success = $true
            Disconnect-VIServer -Server $connection -Confirm:$false | Out-Null
        "" | Select-Object @{Name="VMHost"; Expression={$h}}, @{Name="LoginSuccess"; Expression={$success}}

Leave a Comment

Your email address will not be published.