Hi guys,
I am looking power cli script which can find Below information for 100 esxi host
1:- Network driver details ( Name , Model)
2:- HBA driver details
3:- Netwrok driver firmware version ( Name, Model)
4:- HBA driver Firnware version
5:- multipathing policy
6:- multipathing driver detials
7:- VID
8:- DID
9:- SVID
10 SDID
Regards,
Triyambak
Hi Triyambak,
The cmdlets Get-VMHostHba and Get-VMHostNetworkAdapter give you a list of adapters to use. Some of the information you want can then be obtained using the ESXCLI functionality exposed through PowerCLI- For example this gets the driver info for vmnic0 on the host $MyHost.
PowerCLI C:\> $esxcli=Get-EsxCli -VMHost $MyVMHost
PowerCLI C:\> $esxcli.network.nic.get("vmnic0").DriverInfo | Format-List
BusInfo : 0000:01:00.0
Driver : tg3
FirmwareVersion : FFV7.8.16 bc 5720-v1.32
Version : 3.129d.v50.1
or for the HBA details, use
PowerCLI C:\> $esxcli.iscsi.adapter.get('vmhba38')
Hope that helps get you started!
Chris.
I was looking for the same for some 200 ESXi hosts. But challenge is over 50% of them are not in vCenter.
If you can provide a wayout here ?
like :-
* fetch the list of ESXi from any .csv/txt file.
* login to each host ( all has same root password)
* fetch those details.
* report saved in any .csv/txt file.
*** no. of NIC cards attached attached to each host in UP state.
Hi @MukeshSingh92 - the following !PowerCLI should help you here. Feed it a list of hosts- one per line- in a text file
#Declare an array to hold results
$Results=@()
#Read in the file line by line
Get-Content hosts.txt |Foreach-Object {
#Create a VI Credential Item for this server - they all have the same root password
New-VICredentialStoreItem -Host $_ -User root -Password MyPassword
#Connect to the Server
Connect-VIServer $_ -WarningAction SilentlyContinue -Verbose
#Count the Physical NICs which are connected
$NicCount=(Get-VMHostNetworkAdapter | Where-Object {$_.Id -like "*PhysicalNic*" -and $_.BitRatePerSec -gt 0}).Count
#Disconnect from the server
Disconnect-VIServer -Force -Confirm:$false
#Add the results (hostname, NIC Count) to the array
$Results+=(New-Object -TypeName PSObject -Property @{'Host'=$_;'NIC Count'=$NicCount})
}
#Display the results in a table
$Results | Format-Table
hello chs1 this one works fine. But can you tweak this script to get other details.
Like I need to get the details of each esxi's ( Version and Build). from the same host.txt.
I have tried many option but it doesn't work out.
Hello MukeshSingh92
Version and Build of an ESX host are available through the Get-VMHost cmdlet. After connecting to a host we can run this and get the details of the host- normally the default table view that is returned will restrict what we see but if we pipe the command into Format-List we see all the fields in the object. For example
PS> Get-VMHost | Format-List
State : Connected
ConnectionState : Connected
PowerState : PoweredOn
VMSwapfileDatastoreId :
VMSwapfilePolicy : WithVM
ParentId : Folder-ha-folder-host
IsStandalone : True
Manufacturer : Dell Inc.
Model : PowerEdge R720
NumCpu : 16
CpuTotalMhz : 41584
CpuUsageMhz : 324
LicenseKey : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
MemoryTotalMB : 196562.4765625
MemoryTotalGB : 191.95554351806640625
MemoryUsageMB : 27905
MemoryUsageGB : 27.2509765625
ProcessorType : Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz
HyperthreadingActive : True
TimeZone : UTC
Version : 6.0.0
Build : 4192238
.... etc
So we can take this information and add it into your previous script. Something like this (changes in bold, red):
#Declare an array to hold results
$Results=@()
#Read in the file line by line
Get-Content hosts.txt |Foreach-Object {
#Create a VI Credential Item for this server - they all have the same root password
New-VICredentialStoreItem -Host $_ -User root -Password MyPassword
#Connect to the Server
Connect-VIServer $_ -WarningAction SilentlyContinue -Verbose
#Count the Physical NICs which are connected
$NicCount=(Get-VMHostNetworkAdapter | Where-Object {$_.Id -like "*PhysicalNic*" -and $_.BitRatePerSec -gt 0}).Count
#Get the Host Version and Build
$HostVersion=(Get-VMHost).Version
$HostBuild=(Get-VMHost).Build
#Disconnect from the server
Disconnect-VIServer -Force -Confirm:$false
#Add the results (hostname, NIC Count) to the array
$Results+=(New-Object -TypeName PSObject -Property @{'Host'=$_;'NIC Count'=$NicCount;'Version'=$HostVersion;'Build'=$HostBuild})
}
#Display the results in a table
$Results | Format-Table
The Scirpt runs, takes credentials for each hosts one by one, and then disconnects. but doesn't produces any results. End with an error/exception I have provided as "attachment."
Can you do the changes below :-
1) Credentials is common for all, so enter the credentials once in beginning of programs > store that and use it for repeatedly.
2) produce the output in any csv/txt file.
chs1
MukeshSingh92
A Couple of Suggestions:
1-Have you replaced "MyPassword" in the script with your standardised host root password? If so, you shouldn't be getting prompted for credentials on each host
2-For the errors- Were you already connected to a vCenter before running the script? Try
Disconnect-VIServer
before running the script again to make sure there's no existing connections that would confuse it.
3-To output the result to a text file either use console redirection ( >myfile.txt) or you could use the Export-CSV cmdlet, something like
$Results | Export-CSV myfile.csv
Hope this helps.
Chris.
# Yes. I tried with manually entering the password, still it gives a pop up for credentials.
# Was disconnected as well. didn't worked.
Now I tried the below editing, it just asked for password once and then silently continued, generated a CSV file as well. ... plz see the tweaking I did ( it works now perfectly).
If you got any suggested, Kinldy go ahead.
#Declare an array to hold results
$cred = Get-Credential
$Results=@()
#Read in the file line by line
Get-Content E:\Mukesh\hosts1.txt |Foreach-Object {
#Create a VI Credential Item for this server - they all have the same root password
#New-VICredentialStoreItem -Host $_ -Credential $cred
#Connect to the Server
Connect-VIServer -Server $_ -Credential $cred
#Count the Physical NICs which are connected
$NicCount=(Get-VMHostNetworkAdapter | Where-Object {$_.Id -like "*PhysicalNic*" -and $_.BitRatePerSec -gt 0}).Count
#Get the Host Version and Build
$HostVersion=(Get-VMHost).Version
$HostBuild=(Get-VMHost).Build
#Disconnect from the server
Disconnect-VIServer -Force -Confirm:$false
#Add the results (hostname, NIC Count) to the array
$Results+=(New-Object -TypeName PSObject -Property @{'Host'=$_;'NIC Count'=$NicCount;'Version'=$HostVersion;'Build'=$HostBuild})
}
#Display the results in a table
$Results | Export-Csv E:\Mukesh\report.csv -NoTypeInformation -UseCulture
Hello chs1
need to write a fresh script to pull out all the VMs hosted on all the ESXi.
flow should be :-
1) take the list of esxi from any text file.
2) populate all the vMs per ESXi hosts. ( if some attributes like VM OS can extracted, that will be great )
3) get the details exported in an excel file.
# challenge I faced in the 3rd step. when the output becomes garbage as capturing the date in a perfect rows:column ratio become problematic.
How can make my csv file flexible enough to create "n" rows and stuff...etc etc.
# Lets work it out. Can you help me with a fresh script here.
Hello chs1, Can we also fetch 2 things ( Lincense key and Lincense type ). I tried a few ways, but they all failed.
in this same Script, can you suggest a few modification to get those 2 details per host.