Hi,
Need to get the storage adaptert hardware details like firmware version, driver version etc using shell script. Anyone please help me ?
Regards,
Rajesh
The sample output should be
ClusterName | Hostname | HBA | Model Name | Driver Version | Firmware Version
Hi Rajesh,
I am in need of collecting HBA card details, whihch all are mentioned above by you. Could you please give me the consolidated script to get all those details. If possible, provide me step by step procedures to do that. I believe that you successfully made scripts to fetch all the information that are required.
Any inputs from you, mostly appreciated.
Thanks,
Ganesh
Luc,
I used to get the esxi hosts fw & driver info, network fw & driver info using plink.exe and with your script on how to use it.
But,
Both HBA & NIC details extraction are carried out using seperate scripts , I could not combine both the scripts into a single script to extract all bios FW/ver, HBA & NIC FW driver details into a single CSV.
I used to get these details seperately and using vlookup table I will try to get all the outputs into a single sheet, though to collect NIC details is bit difficult again as each and every hosts have NICs upto 8 in no. struggle to write the table formula
request your help to collide the scripts to use single script with plink.exe to extract all the hosts
Bios FW/driver ver, HBA FW/driver ver, NIC FW/driver ver.
Regards,
Arvinth
Hi Arvinth, this is a rather old thread.
Can you attach both scripts, so I can have a look how to combine the output in 1 CSV ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this.
$ExportFilePath = "C:\HostInfo.csv"
$PuttyUser = "root"
$PuttyPwd = "*******"
$Plink = "C:\Test\Plink.exe"
$PlinkOptions = " -v -batch -pw $PuttyPwd"
$cmd1 = 'cat /proc/scsi/qla*/*' $RCommand0 = "ethtool -i "
$cmd2 = 'cat /proc/scsi/qla*/*' $RCommand1 = '"' + $cmd2 + '"' $qlR1 = [regex]"QLogic.+for\s(\w+):" $qlR2 = [regex]"Firmware version ([\d|\.]+).+Driver version ([\d|\.]+)" # $ESXHosts = Get-cluster XLP-XLP-XLP | Get-Vmhost | Sort Name $ESXHosts = Get-cluster MyCluster | Get-Vmhost $Report = @() ForEach ($ESXHost in $ESXHosts) { $row = "" | Select Hostname,ESXVersion,BiosVersion,BIOSDate
$row.HostName = $ESXHost.Name
$row.ESXVersion = $ESXHost.Version
$row.BiosVersion = $ESXHost.ExtensionData.hardware.biosinfo.biosversion
$row.BiosDate = $ESXHost.ExtensionData.hardware.biosinfo.releasedate
$pNics = $ESXHost | Get-VMHostNetworkAdapter -physical
$i = 1
ForEach ($pNic in $pNics) { $command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $ESXHost.Name + " " + $RCommand0 + " " + $pNic.Name
$Message = Invoke-Expression -command $command
$row | Add-Member -Name pNICName$i -Value $pNic.Name -MemberType NoteProperty
$row | Add-Member -Name DriverName$i -Value ($Message[0] -split "driver: ")[1] -MemberType NoteProperty
$row | Add-Member -Name DriverVersion$i -Value ($Message[1] -split "version: ")[1] -MemberType NoteProperty
$row | Add-Member -Name DriverFirmware$i -Value ($Message[2] -split "firmware-version: ")[1] -MemberType NoteProperty
$i++
} $command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $ESXHost.Name + " " + $RCommand1
$msg = Invoke-Expression -command $command $i = 1
$msg | % { if($_ -match $qlR1){ $row | Add-Member -Name HBAtype$i -Value $qlR1.Match($_).Groups[1].Value -MemberType NoteProperty
} if($_ -match $qlR2){ $matches = $qlR2.Match($_) $row | Add-Member -Name HBAfirmware$i -Value $matches.Groups[1].Value -MemberType NoteProperty
$row | Add-Member -Name HBAdriver$i -Value $matches.Groups[2].Value -MemberType NoteProperty
$i++
} } $report += $row} IF ($Report -ne "") { $Report | Sort-Object -Descending -Property {$_ | Get-Member -MemberType NoteProperty | Measure-Object | Select -ExpandProperty Count} | Export-Csv $ExportFilePath -NoTypeInformation -UseCulture Invoke-Item $ExportFilePath
}
Since there are a variable number of pNICs and HBA, and since you want to combine all that info in 1 row, I created properties with a number of that end of the name for pNICs and the HBA information.
To avoid the Export-Csv problem with arrays with variable record lengths, I sort the array rows in descending order based on the number of properties.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks for this script luc,
the script executed successfully without any errors though it has not created any report in the defined location
I tried eliminating the file path though no luck.
I could also see the key exchange, authentication and session eshtablishment everything during the script execution
but no output
below the is the script which was executed.
$ExportFilePath = "C:\HostInfo.csv"
$PuttyUser = "root"
$PuttyPwd = "*******"
$Plink = "C:\Temp\Plink.exe"
$PlinkOptions = " -v -batch -pw $Puttypwd"
$cmd1 = 'cat /proc/scsi/qla*/*'
$RCommand0 = "ethtool -i "
$cmd2 = 'cat /proc/scsi/qla*/*'
$RCommand1 = '"' + $cmd2 + '"'
$qlR1 = [regex]"QLogic.+for\s(\w+):"
$qlR2 = [regex]"Firmware version ([\d|\.]+).+Driver version ([\d|\.]+)"
$ESXHosts = Get-cluster XLP-XLP-XLP | Get-Vmhost
$Report = @()
ForEach ($ESXHost in $ESXHosts) {
$row = "" | Select Hostname,ESXVersion,BiosVersion,BIOSDate
$row.HostName = $ESXHost.Name
$row.ESXVersion = $ESXHost.Version
$row.BiosVersion = $ESXHost.ExtensionData.hardware.biosinfo.biosversion
$row.BiosDate = $ESXHost.ExtensionData.hardware.biosinfo.releasedate
$pNics = $ESXHost | Get-VMHostNetworkAdapter -physical
$i = 1
ForEach ($pNic in $pNics) {
$command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $ESXHost.Name + " " + $RCommand0 + " " + $pNic.Name
$Message = Invoke-Expression -command $command
$row | Add-Member -Name pNICName$i -Value $pNic.Name -MemberType NoteProperty
$row | Add-Member -Name DriverName$i -Value ($Message[0] -split "driver: ")[1] -MemberType NoteProperty
$row | Add-Member -Name DriverVersion$i -Value ($Message[1] -split "version: ")[1] -MemberType NoteProperty
$row | Add-Member -Name DriverFirmware$i -Value ($Message[2] -split "firmware-version: ")[1] -MemberType NoteProperty
$i++ }
$command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $ESXHost.Name + " " + $RCommand1
$msg = Invoke-Expression -command $command
$i = 1
$msg | % {
if($_ -match $qlR1){
$row | Add-Member -Name HBAtype$i -Value $qlR1.Match($_).Groups[1].Value -MemberType NoteProperty
}
if($_ -match $qlR2){
$matches = $qlR2.Match($_)
$row | Add-Member -Name HBAfirmware$i -Value $matches.Groups[1].Value -MemberType NoteProperty
$row | Add-Member -Name HBAdriver$i -Value $matches.Groups[2].Value -MemberType NoteProperty
$i++
}
}
$report += $row}
IF ($Report -ne "") {
$Report |
Sort-Object -Descending -Property {$_ | Get-Member -MemberType NoteProperty |
Measure-Object | Select -ExpandProperty Count} | Export-Csv $ExportFilePath -NoTypeInformation -UseCulture
Invoke-Item $ExportFilePath}
Is there no file C:\HostInfo.csv created ?
Or is it an empty file ?
Can you try with another folder/filename ? Perhaps it's a permission thing in the filesystem.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Good day & good morning.
I could not test it for the past weekend Luc,
I tried today with a directory specified. the same results everything is getting executed successfully but no results got saved to the location.
Could not find any errors at all 😞
Arvinth
Is the CSV file created at all ?
If the file already exists, please delete the file and run the script again. Just to check if the script executes the Export-Csv cmdlet.
If the file is created but empty, then it looks as if the array is empty for whatever reason.
Can you eventually attach the script you are using in a text file, so I can have a closer look ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, tested your copy of the script, just changed the root password and the clustername, and it works perfect in my test environment.
Could it be that you do not have the SSH fingerprint for the ESXi servers in the cluster stored on the client where you run the script ?
Since the plink.exe is called with the batch parameter, there will be no prompt.
If the fingerprint is not present the call to plink.exe will fail, and the script will continue.
One way of testing this is to launch the plink.exe manually without the batch parameter from the prompt, and check if there are any messages.
Something like this for example:
PS C:\> plink.exe root@myesx ls
This will try to perform a 'ls' command on server myesx with a SSH session with account root.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
From your response I understand that something in my environment is preventing the script from getting the output
But with respect to the SSH fingerprint I have tested it manually as per your advice. I get the root session eshtablished as well & no certificate or warning message saying that plink cache has to be updated with the new ssh fingerprint
Also I have appended the output of a single esxi server in a cluster where i executed this script, from this output I assume that Plink.exe has been successfully called by the script!! not sure if i am correct.
Looking up host "testing1"
Connecting to 10.10.10.15 port 22
Server version: SSH-2.0-OpenSSH_5.6
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.62
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-256
Host key fingerprint is:
ssh-rsa 2048 a1:31:16:85:79:cd:12:b0:56:38:33:56:58:f4:55:7e
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "root".
Attempting keyboard-interactive authentication
Access granted
Opened channel for session
Started a shell/command
Server sent command exit status 0
Disconnected: All channels closed
I don't get the line
Attempting keyboard-interactive authentication
This is from the script when I run it
Looking up host "ESX1"
Connecting to 168.192.12.11 port 22
Server version: SSH-2.0-OpenSSH_5.6
We claim version: SSH-2.0-PuTTY_Release_0.60
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-256
Host key fingerprint is:
ssh-rsa 2048 14:48:da:3f:d6:51:b5:7f:be:3d:30:ba:42:2f:34:d3
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "root".
Access granted
Opened channel for session
Started a shell/command
Server sent command exit status 0
Disconnected: All channels closed
I'm using an older plink version (version 0.60) it seems, but I'm not sure if that could be causing the problem.
Is the 'batch' option I used in the script supported, just do a 'plink' at the prompt, it should give the valid parameters.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
New year wishes to you :-)))
The batch option is getting listed in the prompt , I tried with the other enviroment that we have as well.
same kind of issue and keyboard authentication is attempted
C:\temp>plink.exe
PuTTY Link: command-line connection utility
Release 0.62
Usage: plink [options] [user@]host [command]
("host" can also be a PuTTY saved session name)
Options:
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-v show verbose messages
-load sessname Load settings from saved session
-ssh -telnet -rlogin -raw -serial
force use of a particular protocol
-P port connect to specified port
-l user connect with specified username
-batch disable all interactive prompts
The following options only apply to SSH connections:
-pw passw login with specified password
-D [listen-IP:]listen-port
Dynamic SOCKS-based port forwarding
-L [listen-IP:]listen-port:host:port
Forward local port to remote address
-R [listen-IP:]listen-port:host:port
Forward remote port to local address
-X -x enable / disable X11 forwarding
-A -a enable / disable agent forwarding
-t -T enable / disable pty allocation
-1 -2 force use of particular protocol version
-4 -6 force use of IPv4 or IPv6
-C enable compression
-i key private key file for authentication
-noagent disable use of Pageant
-agent enable use of Pageant
-m file read remote command(s) from file
-s remote command is an SSH subsystem (SSH-2 only)
-N don't start a shell/command (SSH-2 only)
-nc host:port
open tunnel in place of session (SSH-2 only)
-sercfg configuration-string (e.g. 19200,8,n,1,X)
Specify the serial configuration (serial only)
I just tested with the newer PuTTY Suite (0.62) and the script produces results.
I do see the message as well now, so that seems to be something from the new version, but it has no effect on the functioning of the script.
Looking up host "MyEsx"
Connecting to 168.192.22.11 port 22
Server version: SSH-2.0-OpenSSH_5.6
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.62
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-256
Host key fingerprint is:
ssh-rsa 2048 14:48:da:3f:d6:51:b5:7f:be:3d:30:ba:42:2f:34:d3
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "root".
Attempting keyboard-interactive authentication
Access granted
Opened channel for session
Started a shell/command
Server sent command exit status 0
Disconnected: All channels closed
Try changing the last part of the script
IF ($Report -ne "") { $Report | Sort-Object -Descending -Property {$_ | Get-Member -MemberType NoteProperty | Measure-Object | Select -ExpandProperty Count} | Export-Csv $ExportFilePath -NoTypeInformation -UseCulture Invoke-Item $ExportFilePath
}
with just
$report
That way the result will appear on screen and we are sure the data is at least collected.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am really finding the hard time my dear friend..
Still could not even smell the reason for this issue, i tried with just the report option as adviced by you.
still i do not get the report on the screen. and no errors as well.
😞
Sorry, but I have no further ideas what can go wrong with the script in your environment.
In my environment it works.
A possible way to go would be to start the script in a debugger (PowerShell Plus or PowerGUI, both free), set seom breakpoints and validate the script step-by-step.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Np My friend, I shall try to sort using the tool as per your advice.
I would like to thank you for the guidance really appreciated.
have a good day.