Hi Admins,
After searching the community I got some script on Service Tag and I modified the script slightly. However I am not getting the expected results. Could you please check and update the below code?
My Script:
$user = 'userid@company.net'
$pswd = 'password'
Import-Csv -Path .\Host.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
try
{
(Get-VMHost $row.host | Get-View).Summary.Hardware.OtherIdentifyingInfo[0].IdentifierValue
$result = ""
}
catch
{
$result = "null"
}
$row | Add-Member -MemberType NoteProperty -Name 'result' -Value $result -PassThru
# $row | Add-Member -MemberType NoteProperty -Name 'vCenter' -Value $@{N ="vCenter";E={([uri]$_.ExtensionData.Client.ServiceUrl).Host}} -PassThru
} | Export-Csv -Path .\servicetags-result.csv -NoTypeInformation
Expected Output:
servicetags result vCenter
hostname1.site1.domain.net DellServiceTag1 vCenter1.site1.domain.net
hostname2.site1.domain.net DellServiceTag2 vCenter1.site1.domain.net
hostname1.site2.domain.net DellServiceTag3 vCenter2.site2.domain.net
hostname1.site2.domain.net DellServiceTag4 vCenter2.site2.domain.net
hostname1.site3.domain.net DellServiceTag5 vCenter3.site3.domain.net
But getting the output as below:
Length
7
7
7
7
Message was edited by: User. Updated the code, code output & attached file.
Can you give it a try like this?
$pswd = 'password'
Import-Csv -Path .\Host.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$esx = Get-VMHost $row.host -ErrorAction SilentlyContinue
$result = ''
if($esx){
$result = $esx.ExtensionData.Summary.Hardware.OtherIdentifyingInfo[0].IdentifierValue
}
$row | Add-Member -MemberType NoteProperty -Name 'result' -Value $result -PassThru
} | Export-Csv -Path .\servicetags-result.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are sure your CSV file contains a column with the name 'host'?
Also, I'm not sure what you are trying to do in the try-block.
You fect a value, which is then placed in the pipeline.
And then there is the line with $result = '', not sure what the purpose of that is.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LuCD,
Thank you for the response. I have attached my csv as well as made some minor changes to the code but still it is not working.
Hence request you to please ignore my errors in it and modify as necessary to show the mentioned output in my First Post?
Can you give it a try like this?
$pswd = 'password'
Import-Csv -Path .\Host.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$esx = Get-VMHost $row.host -ErrorAction SilentlyContinue
$result = ''
if($esx){
$result = $esx.ExtensionData.Summary.Hardware.OtherIdentifyingInfo[0].IdentifierValue
}
$row | Add-Member -MemberType NoteProperty -Name 'result' -Value $result -PassThru
} | Export-Csv -Path .\servicetags-result.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thank you for the quick response and the code. I see now it is not giving any errors and providing a result but not as expected.
Our device is a Nutanix Box and it has Dell nodes in it. So the code returns the serial number of the Nutnaix box where the output is same for all 4 servers in it.
But that is another problem afaik, which you probably should raise in the HCI vendor's forum.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
After digging some post, I got the below code. It fits almost my requirement, it doesn't have vCenter name and it doesn't export to a csv. Please add the vCenter name to the below code and make it exported to csv.
$hostname = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo
foreach ($hname in $hostname)
{
$hn = $hname.name
$Man = $hname.Hardware.SystemInfo.Vendor
$Mod = $hname.Hardware.SystemInfo.Model
$serviceTag = $($hname.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue
$hname | Add-Member -MemberType NoteProperty -Name VMHost -Value $hn
$hname | Add-Member -MemberType NoteProperty -Name OEM -Value $Man
$hname | Add-Member -MemberType NoteProperty -Name Model -Value $Mod
$hname | Add-Member -MemberType NoteProperty -Name ServiceTag -Value $serviceTag
}$hostname | select VMHost, OEM, Model, ServiceTag
My actual requirement is to perform a upgrade/maintenance activity during this Christmas time for our all servers. So it would be very helpful to have the list of all servers with detailed information such as
vCentername vCenterUUID Server/hostname ModelNo ServiceTag Warranty ESXiVersionName BIOS AdapterFirmware NetworkDriver FCDriver HBAModel HBADriver HBAModule HBAVersion
I have the below code can this be updated to reflect the above said fields? If the field Warranty is unable to be fetched then that can be skipped as it not required for the upgrade activity but for a later use.
$ResultFile = "C:\temp\Result.CSV"
$vmhosts = Get-Datacenter | Get-VMHost
$report = @()
foreach ( $ESXHost in $vmhosts)
{
$HWModel = Get-VMHost $ESXHost
$esxcli = Get-EsxCli -vmhost $ESXHost
$info = $esxcli.network.nic.get("vmnic0")
$elxnet = $esxcli.software.vib.list() | Where-Object { $_.name -eq "elxnet" }
$lpfc = $esxcli.system.module.list() | Where-Object { $_.Name -eq '*' }
if ($lpfc)
{
$lpfc = $esxcli.system.module.get("*")
}
$report += $ESXHost |
Select-Object @{N = "Hostname"; E = { $_.Name } },
@{N = "IPAddress"; E = { ($_ | Get-VMHostNetwork).VirtualNic | Where-Object { $_.ManagementTrafficEnabled } | Select-Object -ExpandProperty IP } },
Manufacturer,
ProcessorType,
@{N = "BIOS version"; E = { $_.ExtensionData.Hardware.BiosInfo.BiosVersion } },
@{N = "Hardware-Model"; E = { $HWModel.Model } },
@{N = "Adapter-Firmware"; E = { $info.DriverInfo.FirmwareVersion } },
@{N = "Network-Driver"; E = { $info.DriverInfo.Version } },
@{N = "FC-Driver"; E = { $elxnet.version.substring(0, 14) } },
@{N = "HBA Model"; E = { ($_ | get-vmhosthba | select-object -ExpandProperty Model) -join ", " } },
@{N = "Driver"; E = { ($_ | get-vmhosthba | select-object -ExpandProperty Driver) -join ", " } },
@{N = 'HBA-Module'; E = { $lpfc.Module } },
@{N = 'HBA-Version'; E = { $lpfc.Version } }
}
$report | Export-Csv -Path $ResultFile -NoTypeInformation
I also get this below warning as well.
Warning:
PS C:\temp> .\GetEsxinfo.ps1
WARNING:
The Get-EsxCli cmdlet provides a new interface to the ESXCLI functionality.
Use the -V2 parameter to switch to the new cmdlet interface.
Check the cmdlet help for more information.
Scripts that use the old cmdlet interface may not be compatible across two different versions of the ESX server.
The old cmdlet interface is deprecated and will be removed in a future version.
WARNING: The 'VirtualNic' property of VMHostNetworkInfo type is deprecated. Use 'Get-VMHostNetworkAdapter' cmdlet
instead.
My CLI version is 11.5 and all of the components are recently updated.
*****************************************************************************************************************************************
PowerCLI Version
----------------
VMware PowerCLI 11.5.0 build 14912921
---------------
Component Versions
---------------
VMware Common PowerCLI Component 11.5 build 14898112
VMware Cis Core PowerCLI Component PowerCLI Component 11.5 build 14898113
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.5 build 14899560
VMWare ImageBuilder PowerCLI Component 6.7 build 11233116
VMWare AutoDeploy PowerCLI Component 6.7 build 11233116
VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 11.2 build 12483615
VMware VimAutomation Cloud PowerCLI Component PowerCLI Component 11.0 build 10379994
VMware High Availability PowerCLI Component 6.0 build 000000
VMware HorizonView PowerCLI Component 7.1.0 build 14653756
VMware VimAutomation License PowerCLI Component PowerCLI Component 11.3 build 13990093
VMware VimAutomation PCloud PowerCLI Component PowerCLI Component 10.0 build 7893924
VMware VimAutomation Storage PowerCLI Component PowerCLI Component 11.5 build 14901686
VMware VimAutomation vROps PowerCLI Component PowerCLI Component 10.0 build 7893921
VMware vSphere Update Manager PowerCLI 6.5 build 7862888
*****************************************************************************************************************************************
Try like this
ForEach-Object -Process {
New-Object PSObject -Property @{
VMHost = $_.Name
OEM = $_.Hardware.SystemInfo.Vendor
Model = $_.Hardware.SystemInfo.Model
SeviceTag = $($_.Hardware.SystemInfo.OtherIdentifyingInfo | where { $_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue
vCenter = ([uri]$_.Client.ServiceUrl).Host
}
} | Select VMHost, OEM, Model, ServiceTag, vCenter |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
The Get-EsxCli warning is just that, a warning.
You should start using the V2 switch, but note that the methods are invoked slightly different.
See PowerCLI 6.3 R1: Get-ESXCLI Why the V2? for more details.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
The provided code gives the data and export but except for ServiceTag.
I am getting the ServiceTag filed is blank rest other colums are having valid data.
Also could you kindly provide me the code for the second question(updated in red now) in my previous post?
I used the exact same code as your script, so that property shouldn't have been there in your script either.
Note that the layout of and the values in the OtherIdentifyingInfo property are marked with "This information may be vendor specific" in the HostSystemInfo object documentation.
There is no guarantee that you will actually get a meaningfull value from there.
It is the HW Vendor that decides if and what goes in there.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Btw, for obtaining HW info from the box, I would suggest having a look at the HW vendor's set of cmdlets.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for the response LucD. I understand now.
Could you kindly look into my second question in my previous post where I am searching for the below info for servers. Can this be provided to me as well?
vCentername vCenterUUID Server/hostname ModelNo ServiceTag Warranty ESXiVersionName BIOSVerison AdapterFirmware NetworkDriver FCDriver HBAModel HBADriver HBAModule HBAVersion
The 2nd script you mentioned has most of that information if I understand correctly.
What is missing?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The missing info is
ESXiVersionName HBAModel HBADriver HBAModule HBAVersion
Also in my script the output for "HBAModel HBADriver HBAModule HBAVersion" are blank or sometimes it gives the below info
HBA Model
Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, 88SE9230 PCIe SATA 6Gb/s Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, 88SE9230 PCIe SATA 6Gb/s Controller, Lewisburg SATA AHCI Controller, 88SE9230 PCIe SATA 6Gb/s Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller, Lewisburg SATA AHCI Controller
Driver
ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci, ahci
HBA-Module
HBA-Version
The following uses the V2 version of Get-EsxCli.
I'm not sure what your are trying to get into $lpfc. Afaik there are no modules with the name '*'.
That you get multiple values in some properties is due to the -join operator.
Get-Datacenter | Get-VMHost |
ForEach-Object -Process {
$hba = Get-VMHostHba -VMHost $_
$esxcli = Get-EsxCli -VMHost $_ -V2
$info = $esxcli.network.nic.get.Invoke(@{nicname='vmnic0'})
$elxnet = $esxcli.software.vib.list.Invoke() | Where-Object { $_.name -eq 'elxnet' }
$lpfc = $esxcli.system.module.list.Invoke() | Where-Object { $_.Name -like '*' }
New-Object PSObject -Property @{
HostName = $_.Name
ESXiVersion = $_.Version
IPAddress = ($_ | Get-VMHostNetwork).VirtualNic | Where-Object { $_.ManagementTrafficEnabled } | Select-Object -ExpandProperty IP
Manufacturer = $_.Manufacturer
ProcessorType = $_.ProcessorType
'BIOS version' = $_.ExtensionData.Hardware.BiosInfo.BiosVersion
'Hardware-Model' = $_.Model
'Adapter-Firmware' = $info.DriverInfo.FirmwareVersion
'Network-Driver' = $info.DriverInfo.Version
'FC-Driver' = $elxnet.version.substring(0, 14)
'HBA Model' = $hba.Model -join ", "
'Driver' = $hba.Driver -join ", "
'HBA-Module' = $lpfc.Module
'HBA-Version' = $lpfc.Version
}
} | Export-Csv -Path $ResultFile -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The code worked flawlessly. Thank you so much for all your efforts and patience. I have commented the $lpfc as I do not remember what I had created earlier for.
Once again A BIG THANK YOU AND I SINCERELY APPRECIATE YOUR EFFORTS on this.