I tried to get all of my Host Serial number information by useing this one liner:
Get-View -ViewType HostSystem | Select Name,@{N="Tag";E={$_.Summary.Hardware.OtherIdentifyingInfo[1].IdentifierValue}}
This lists all of my hosts, however it just lists one serial num for one host.
See attached screenshot.
Thanks in advance..
The link is to a function.
You can add it to the script from Carter or you can store it in another .ps1 file which you dot-source.
With dot-sourcing the functions defined in a .ps1 file are known in your session, and hence in the scripts you start from your session.
Dot-sourcing is done like this (don't forget the blank between the 2 dots).
. ./file.ps1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The serial number has been a pain in the * since day 1.
Not every HW vendor makes it available in the same place.
Have a look at Script to get serial number of all hosts
In there you'll find a CIM based method to retrieve the serial number.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Hi LucD,
I saw this thread and grabbed this one which doesn't work, as my powerCLi doesn't have Get-VMHostWSManInstance as a command.
Also, the other hosts are the same model.
$Credential = Get-Credential
Get-VMHost | ForEach-Object {
$VMHost = $_
$PhysicalPackage = Get-VMHostWSManInstance -VMHost $_ -class CIM_PhysicalPackage -ignoreCertFailures -credential $Credential | `
Where-Object {$_.ElementName -eq "Chassis"}
$Report = "" | Select-Object -Property VMHost,SerialNumber
$Report.VMHost = $VMHost.Name
$Report.SerialNumber = $PhysicalPackage.SerialNumber
$Report
} | Export-Csv -NoTypeInformation -UseCulture -Path c:\Temp\EsxSerialNumbers.csv
You'll find the Get-VMHostWSManInstance function here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD, The link abbove that you gave me, Should I just copy the scirpt and save it to a ps1 file and run it after I change to path where it should be saved?
Message was edited by: vite@1
The link is to a function.
You can add it to the script from Carter or you can store it in another .ps1 file which you dot-source.
With dot-sourcing the functions defined in a .ps1 file are known in your session, and hence in the scripts you start from your session.
Dot-sourcing is done like this (don't forget the blank between the 2 dots).
. ./file.ps1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, I see, almost like calling another module and or library, like in some other programming methods. I will try it tomorrow and let you know.
Thanks.
Hi LucD,
So I coppied this whole script and ran it and it worked great. I must have had some typos last time or something. Do you think that the next version of PowerCli cmd Get-VMHostWSManInstance will work and or add this to their comandlets? I'm not sure how that works in the PowerCLI world if they add fucntions to their new builds that permits new cmd that work out of the box??
Thanks a lot for your help:
function Get-VMHostWSManInstance {
param (
[Parameter(Mandatory=$TRUE,HelpMessage="VMHosts to probe")]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl[]]
$VMHost,
[Parameter(Mandatory=$TRUE,HelpMessage="Class Name")]
[string]
$class,
[switch]
$ignoreCertFailures,
[System.Management.Automation.PSCredential]
$credential=$null
)
$omcBase = "http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/"
$dmtfBase = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
$vmwareBase = "http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/"
if ($ignoreCertFailures) {
$option = New-WSManSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
} else {
$option = New-WSManSessionOption
}
foreach ($H in $VMHost) {
if ($credential -eq $null) {
$hView = $H | Get-View -property Value
$ticket = $hView.AcquireCimServicesTicket()
$password = convertto-securestring $ticket.SessionId -asplaintext -force
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $ticket.SessionId, $password
}
$uri = "https`://" + $h.Name + "/wsman"
if ($class -cmatch "^CIM") {
$baseUrl = $dmtfBase
} elseif ($class -cmatch "^OMC") {
$baseUrl = $omcBase
} elseif ($class -cmatch "^VMware") {
$baseUrl = $vmwareBase
} else {
throw "Unrecognized class"
}
Get-WSManInstance -Authentication basic -ConnectionURI $uri -Credential $credential -Enumerate -Port 443 -UseSSL -SessionOption $option -ResourceURI "$baseUrl/$class"
}
}
Get-VMHost | ForEach-Object {
$VMHost = $_
$PhysicalPackage = Get-VMHostWSManInstance -VMHost $_ -class CIM_PhysicalPackage -ignoreCertFailures | Where-Object {$_.ElementName -eq "Chassis"}
$Report = "" | Select-Object -Property VMHost,SerialNumber
$Report.VMHost = $VMHost.Name
$Report.SerialNumber = $PhysicalPackage.SerialNumber
$Report
} | Export-Csv -NoTypeInformation -UseCulture -Path c:\Temp\EsxSerialNumbers.csv
That function is not specific for PowerCLI, so I doubt if it will be added to the PowerCLI snapin.
But one of the stronger features of PowerShell is it's modularity.
You can easily package these functions that you need quite often in a module or in a .ps1 file.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference