What's the best way to pull the report information in and process it? Ideally, I'd like to place the contents into some sort of array and query through that for the different things I want (versions of components etc.). Thanks!
Are there any components that people are aware of that are not contained in the output? Seems to contain a lot of system information (bios version, disk firmware etc.)
$User = "root"
$Pswd = "password"
$Computer = "servername"
$plink = "s:\Putty\plink.exe"
$plinkoptions = " $Computer -l root -pw $Pswd"
# start ssh
get-vmhost $Computer | get-vmhostservice | where { $_.Key -eq "TSM-SSH" } | Start-VMHostService -confirm:$false | Out-Null
$cmd1 = '/usr/lib/vmware/vm-support/bin/swfw.sh > /usr/lib/vmware/vm-support/bin/output.txt'
$remoteCommand = '"' + $cmd1 + '"'
$command = "echo y" + " " + "|" + " " + $plink + " " + $plinkoptions + " " + $remoteCommand
# execute remote command
$msg = Invoke-Expression -command $command
$msg
# turn off ssh
get-vmhost $Computer | get-vmhostservice | where { $_.Key -eq "TSM-SSH" } | Stop-VMHostService -confirm:$false | Out-Null
You seem to redirect the command output to a file on the local filesystem.
Why is that ?
If you let the output come the screen, it should be in the $msg variable afterwards.
And I suspect you easily extract the required info with a RegEx expression.
What information do you want to extract exactly ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You seem to redirect the command output to a file on the local filesystem.
Why is that ?
If you let the output come the screen, it should be in the $msg variable afterwards.
And I suspect you easily extract the required info with a RegEx expression.
What information do you want to extract exactly ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Redirection to the local system was just a step (after local execution) in the direction you've laid out . Thanks, I'll go in that direction.
Right now, looking for as many pieces I can get in that location (bios version/date, disk, network, hba, ilo version etc.). Mainly any components that would be updated during a release cycle for example.
Testing with $msg and querying with regex now, but curious why out-null does not suppress these errors. Assuming it has something to do with the command running remotely on the other system.
$msg = s:\Putty\plink.exe server -l root -pw password "/usr/lib/vmware/vm-support/bin/swfw.sh" | out-null
error: enumInstances Class not found
error: enumInstances Class not found
error: enumInstances Class not found
Is there anything in the $msg variable ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
lol - You guessed it - not with the | out-null on the end
And do you still get the errors when Out-Null is removed ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I do Luc. To add a bit more info here. When running ./swfw.sh on the ESXi server locally this appears at the end.
Namespace: interop
error: enumInstances Class not found
Namespace: vmware/esxv2
error: enumInstances Class not found
Namespace: root/config
error: enumInstances Class not found
This may add a little more challenge. So, I've been able to:
Loop through a list of servers or entire VC:
1. enable SSH
2. export output from swfw.sh to the local filesystem of the powercli box (servername.txt).
3. disable SSH
Plan is to now parse through this data and clean it up to get the exact data I want. Looking for the best way to create objects with the data. Here is a snippet of the output:
ELXUCNA_DiagnosticIdentity.InstanceID="ELXUCNA: NIC PHY LoopBackTest"
InstanceID = ELXUCNA: NIC PHY LoopBackTest
ElementName = ELXUCNA: NIC PHY LoopBackTest
Description = ELX UCNA: Diagnostics
Name = ELXUCNA: NIC PHY LoopBackTest
MajorVersion = 1
MinorVersion = 4
RevisionNumber = 1
IsLargeBuildNumber = false
VersionString = 1.4.1
Manufacturer = Emulex
Classifications = { 7, }
ClassificationDescriptions = { ELX UCNA Diagnostics, }
IsEntity = true
Namespace: root/cimv2
OMC_MCFirmwareIdentity.InstanceID="46.10000"
InstanceID = 46.10000
IsEntity = true
Classifications = { 8, }
IsLargeBuildNumber = false
OperationalStatus = { 0, }
Description = BMC Firmware (node 0) 46:10000
Caption = BMC Firmware (node 0) 46:10000
ElementName = BMC Firmware (node 0) 46:10000
Manufacturer = Hewlett-Packard
Name = Baseboard Management Controller
VersionString = 1.1
EnabledState = 0
OMC_SMASHFirmwareIdentity.InstanceID="34.0"
InstanceID = 34.0
IsLargeBuildNumber = true
VersionString = I31
ReleaseDate = 20120221000000.000000+000
Name = System BIOS
Manufacturer = HP
IsEntity = true
ElementName = System BIOS
Caption = System BIOS
I am thinking there is some way to key on the line breaks and the "=" signs to somehow create objects from the data, so I can query through it etc.. Any ideas on how to best parse through the data? For example on the last block of lines I would like to pull out "System BIOS" and the "VersionString" value and the "ReleaseDate" value.
You can try something like this.
It uses a RegEx string in combination with the Select-String cmdlet.
$msg | Select-String -Pattern "VersionString = (?<version>.*)\s.+ReleaseDate = (?<releasedate>.*)\s.+System BIOS" |
Select @{N="Version";E={$_.Matches[0].Groups["version"].Value}},
@{N="ReleaseDate";E={$_.Matches[0].Groups["releasedate"].Value}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey Luc, thanks for the reply. Digging into this one, but that query didn't return anything. Breaking the pieces down now. Also, my colleague has posted on this as well, so sorry for the duplicate angle attack on this one. Thanks again.
It could be that the actual format of the text in $msg is slightly different from what I copied from the thread.
I'll capture the output myself on my test system and check what might be missing in the RegEx expression.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
Worked on a method for getting this done last night. Here is the function I came up with (how do you get syntax highlighting and spacing to look right in the communities for powershell??)
function get-swfw ($vmhost, $cluster, $Plink, $Password){
$User = "root"
$Report = @()
if ($VMhost -ne $null){
$vmhosts = $VMhost
}
if ($cluster -ne $null){
$vmhosts = $cluster | Get-VMHost
}
# Start SSH
$vmhosts | Get-VMHostService | where {$_.Key -like "*SSH*"} | start-VMHostService -Confirm:$false | out-null
Sleep 10
foreach ($VMHost in $VMHosts){
#Define Regexes
$PrimaryKeyValueRegex = [regex]"(\S+)\.InstanceID=(.+)"
$PropertyKeyValueRegex = [regex]"(\S+.)\s=\s(.+)"
$instanceIDs = @()
# Get SWFW Info
$SWFWInfo = '/usr/lib/vmware/vm-support/bin/swfw.sh'
$remoteCommand = '"' + $SWFWInfo + '"'
$command = $plink + " " + "-batch -pw " + "'" + $Password + "'" + " -auto_store_key_in_cache" + " " + $User + "@" + $vmhost.name + " " + $remoteCommand
$SWFWOutput = Invoke-Expression -command $command
# Parse SWFW Info
foreach ($item in $SWFWOutput){
if ($item -like "*.InstanceID=*"){
$InstanceIDs += [array]::IndexOf($SWFWOutput,$item)
}
}
foreach ($item in $instanceIDs){
$number = $item + 1
$object = New-Object –TypeName PSObject
Do {
$Key = $PropertyKeyValueRegex.Match($SWFWOutput[$number]).Groups[1].Value
$Value = $PropertyKeyValueRegex.Match($SWFWOutput[$number]).Groups[2].Value
$object | Add-Member –MemberType NoteProperty –Name $Key –Value $Value
$number = $number + 1
}
Until ($SWFWOutput[$number].length -eq 0)
$Report += $object
}
}
# Stop SSH
$vmhosts | Get-VMHostService | where {$_.Key -like "*SSH*"} | stop-VMHostService -Confirm:$false | out-null
return $Report
}
get-swfw -vmhost (get-vmhost (Read-Host "VMhost Name")) -Plink $Plink -Password (Read-Host "Password") | ft
Great !
I have been looking at the output yesterday as well, and my conclusion was that the output is way too complex to capture the data with 1 RegEx expression.
There might be another way to do it, but I'm still looking at that.
In the end was it your intention to capture all the fields in the output, and present them as 1 or more objects ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This process started as being a very targeted solution for just bios and a few firmware items. But after realizing the kind of data that existed in the output, we decided it would be best to capture it all so we can track other items as well.
HI All, How do i copy these hardware info to a file? As
Will just posted this a few months back. I like it a lot more than swfw. it has most of the info in it that is in swfw if i remember correctly. You can then dump it directly from powershell to a file. http://www.virtuallyghetto.com/2016/06/using-the-vsphere-api-to-remotely-collect-esxi-esxcfg-info.ht...