Hi All, Goodday!
I am looking for a script to list VMs, IP, PowerState and Host details for 1700 stand alone ESXi host. Could you please and guide for the script.
Thank you.
Regards
Assuming the CSV content looks like this
ESXName
esx1
esx2
Try something like this
$user = 'root'
$pswd = 'VMware1!'
$report = @()
Import-Csv -Path vmhost-names.csv -UseCulture | %{
$srv = Connect-VIServer -Server $_.ESXName -User $user -Password $pswd
$report += (Get-VM -Server $srv |
Select Name,PowerState,
@{N='VMHost';E={$_.VMHost.Name}},
@{N='IP';E={$_.Guest.IPAddress -join '|'}})
Disconnect-VIServer -Server $rv -Confirm:$false
}
$report | Export-Csv -Path report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do your VMs all have the VMware Tools installed?
And what do you mean by "Host details"?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, All VMs have VM Tools installed.
I mean VMs name, VMs IP, VMs PowerState and Host Name. I want to collect these information for 1700 ESXi stand alone host and they have common password for time being.
Regards
Are these ESXi hosts all added to a vCenter?
Then you could connect to all vCenters, and do
Get-VM |
Select Name,PowerState,
@{N='VMHost';E={$_.VMHost.Name}},
@{N='IP';E={$_.Guest.IPAddress -join '|'}}
If they are not in a vCenter, then you would need a list somewhere (CSV ?) of the hostnames of all the ESXi nodes.
Is there such a list?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, I have all the list of host names in csv file. Some are added to vCenter and some not. Hence I would like go by calling csv file and i will include credentials in the script as they are common for now.
Assuming the CSV content looks like this
ESXName
esx1
esx2
Try something like this
$user = 'root'
$pswd = 'VMware1!'
$report = @()
Import-Csv -Path vmhost-names.csv -UseCulture | %{
$srv = Connect-VIServer -Server $_.ESXName -User $user -Password $pswd
$report += (Get-VM -Server $srv |
Select Name,PowerState,
@{N='VMHost';E={$_.VMHost.Name}},
@{N='IP';E={$_.Guest.IPAddress -join '|'}})
Disconnect-VIServer -Server $rv -Confirm:$false
}
$report | Export-Csv -Path report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you so much! Its working great and able to collect the information.
Need one more help.
Could you please share the code to collect the ESX host serial number for these 1700 hosts.
Try like this
$user = 'root'
$pswd = 'VMware1!'
$report = @()
Import-Csv -Path vmhost-names.csv -UseCulture | %{
$srv = Connect-VIServer -Server $_.ESXName -User $user -Password $pswd
$report += (Get-VM -Server $srv |
Select Name,PowerState,
@{N='VMHost';E={$_.VMHost.Name}},
@{N='IP';E={$_.Guest.IPAddress -join '|'}},
@{N='VMHost Serial';E={((Get-EsxCli -VMHost $_.VMHost -V2).hardware.platform.get.Invoke()).SerialNumber}})
Disconnect-VIServer -Server $rv -Confirm:$false
}
$report | Export-Csv -Path report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried it, serial number is not capturing, just VMHost Serial number column is created in the report.
And when you change that line with
@{N='VMHost Serial';E={((Get-EsxCli -VMHost $_.VMHost).($esxcli.hardware.platform.get()).SerialNumber).SerialNumber}})
If it does return the serial in that form, it might be time look at upgrading your PowerCLI version.
Have a look at the version with Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, I changed that line while running previously. it did not return the serial number.
I have PowerCLI 5.5 release 1 build 1295336 installed.
Please advise if this version support or which version supports for these commands
This kind of HW information, including the serial number, depends on the HW vendor.
Some vendors make this info available, others don't I'm afraid.
You could try to upgrade your PowerCLI version, but like I said that is no guarantee, it also depends on the HW vendor.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for the update!
All servers Cisco and Dell servers. Is there any possibilities to just collect the serial number.
I'm afraid I don't have access to such HW, so I can't try it out.
Some users seems to have success with $esx.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello everybody check my github repository and you will find 2 scripts:
1- Collect all VMs Info by vCenter with Login/Password
2- Collect all VMs Info by vCenter using AD Account
Nice scripts, but what is the relation of those scripts to this thread?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference