Highlighted
Enthusiast
Enthusiast

Script to Verify Login Credentials of a Host

Jump to solution

Hello Everyone,

I have a list of around 600+ IP Address of hosts machines in different vCenters. I have been asked to verify the our standard login credentials of each machine. As it is a tiredsome task. Can I check with you guys whether is a script which will take an input of IP address in CSV or txt file and it will login to each host machine with the supplied user id and passwords? If yes, could you kindly provide me with a script for the same.

0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

Yes, since these are all ESXi nodes, you can use the Connect-VIServer cmdlet to check the credentials.
Something like this for example.

$user = 'user'

$pswd = 'password'


Import-Csv -Path .\servers.csv -UseCulture -PipelineVariable row |

ForEach-Object -Process {

   try

   {

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

   Disconnect-VIServer -Server $row.Server -Confirm:$false

   $result = 'ok'

   }

   catch

   {

   $result = 'nok'

   }

   $row | Add-Member -MemberType NoteProperty -Name 'Result' -Value $result -PassThru

} | Export-Csv -Path .\servers-result.csv -NoTypeInformation -UseCulture

----------------------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

0 Kudos
10 Replies
Highlighted
User Moderator
User Moderator

What kind of hosts are you targetting?

And what kind of login do you want to test? Is that via a SSH session? A Connect-VIServer? ...


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi LucD,

We have around 20+ vCenters added to our scope of support recently. For these 20 vCenters we around 600+ hosts attached to it and all are ESXi hosts with different versions of Hypervisors running from 5.0 to 6.5. I have gathered the FQDN and IP address of all those sheet in an excel. Now I have given a task to verify those hosts with our default credentials by logging into it via browser  / SSH.

So wanted to check is there a feasibility for the same?

0 Kudos
Highlighted
User Moderator
User Moderator

Yes, since these are all ESXi nodes, you can use the Connect-VIServer cmdlet to check the credentials.
Something like this for example.

$user = 'user'

$pswd = 'password'


Import-Csv -Path .\servers.csv -UseCulture -PipelineVariable row |

ForEach-Object -Process {

   try

   {

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

   Disconnect-VIServer -Server $row.Server -Confirm:$false

   $result = 'ok'

   }

   catch

   {

   $result = 'nok'

   }

   $row | Add-Member -MemberType NoteProperty -Name 'Result' -Value $result -PassThru

} | Export-Csv -Path .\servers-result.csv -NoTypeInformation -UseCulture

----------------------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi LucD,

Thank you for providing the script. Below is the error message which I got when I execute the script. Could you kindly check and advise.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

PowerCLI C:\temp> .\HostInfo.ps1

ConvertFrom-Csv : Cannot validate argument on parameter 'InputObject'. The argument is null or empty. Provide an argument that is not null or

empty, and then try the command again.

At C:\temp\HostInfo.ps1:6 char:30

+ ConvertFrom-Csv -InputObject $data -PipelineVariable row |

+                              ~~~~~

    + CategoryInfo          : InvalidData: (:) [ConvertFrom-Csv], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ConvertFromCsvCommand

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

From the provided script, I have added only our user & password into it.

0 Kudos
Highlighted
User Moderator
User Moderator

Oops, that was a copy/paste mistake.
I updated the code above.


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi LucD,

Thank you for the quick response and updating the code. I have now executed the same and script is getting executed without any issues but not giving the expected results.

I have added the FQDNs into the csv file, but getting the results as nok.

-----------------------------------------------------------------------------------------------------------------------

server.csv contains the below data and I have provided here our default login credentials

Server

hostname1.site.company.net

hostname2.site.company.net

hostname3.site.company.net

hostname4.site.company.net

After executing the script

servers-result.csv contains the below data.

Server                                                      Result

hostname1.site.company.net                   nok

hostname2.site.company.net                   nok

hostname3.site.company.net                   nok

hostname4.site.company.net                   nok

-----------------------------------------------------------------------------------------------------------------------

server.csv contains the below data and I have provided here our default login credentials and then also tried with domain admin credentials (have access to vcenter) but still it is showing as nok.

Server

vcentername1.site.company.net

vcentername2.site.company.net

vcentername3.site.company.net

vcentername4.site.company.net

After executing the script

servers-result.csv contains the below data.

Server                                                      Result

vcentername1.site.company.net              nok

vcentername2.site.company.net              nok

vcentername3.site.company.net              nok

vcentername4.site.company.net              nok

-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Highlighted
User Moderator
User Moderator

I understood the column was named FQDN.
But since you went for Server, I have adapted the code above to reflect that.


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi LucD,

Sorry for the delayed response. I was ill and did not came to office.

I still see the issue persists. Please advise what needs to be provided to you for checking the issue here?

0 Kudos
Highlighted
User Moderator
User Moderator

Can you attach (bottom right button) the script as you are using it?
And a couple of lines from the beginning of the CSV file (you can hide the sensitive information).


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi LucD,

Thank you so much for helping me out. The updated script is working fine.

The mistake I did is in these post I was mentioning the CSV row header as "Server" whereas I was using as "servers" in it. After making these minor corrections in my script it is working flawlessly.

I confirm that I have tested these with vCenters as well as Hosts machines. Both are getting authenticated via this script.

Thank you Once again.

0 Kudos