VMware Cloud Community
IKirill
Enthusiast
Enthusiast

PowerCli-correct password for hosts or not

Hi dear comrades!

I have vcenter 5.1

I have 500 hosts in my infustructure and i have CSV file with dns names of hosts!

i have login and password, but in some cases i cant' login to esxi hosts whith these credentials!

Ok!

I need a script that will connect to all hosts from CSV file, and using the login and password, answer will pass the connection to the host or not.

And take this info to csv, like this:

hostname           |     status

esxi1.corp.com         PASSOK

esxi2.corp.com         PASSBAD

0 Kudos
2 Replies
LucD
Leadership
Leadership

You could try something like this

$user = 'MyUser'

$pswd = 'MyPswd'

$report = Import-Csv hostnames.csv -UseCulture | %{

    Try{

        Connect-VIServer -Server $_.HostName -User $user -Password $pswd -ErrorAction Stop | Out-Null

        $status = 'PASSOK'

        Disconnect-VIServer -Server $_.HostName -Confirm:$false

    }

    Catch{

        $status = 'PASSBAD'

    }

    New-Object PSObject -Property @{

        HostName = $_.HostName

        Status = $status

    }

}

$report | Export-Csv report.csv -NoTypeInformation -UseCulture


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

0 Kudos
IKirill
Enthusiast
Enthusiast

Many thanks!!!\

0 Kudos