Hello everyone, I have created this script to retrieve information as host but can not enter in the first column the name dev VCenter. How can I do ? Thanks so much
$VMHosts = Get-VMHost
$Inventory = ForEach ($VMHost in $VMHosts)
"" | Select-Object -Property @{N="Name";E={$VMHost.Name}}
@{N="Modello";E={(Get-View -ViewType HostSystem -Filter @{"Name" = $VMHost.Name}).Hardware.Systeminfo.Model}},
@{N="IP MGT";E={(Get-VMHostNetworkAdapter -VMHost $VMHost.Name -name "vmk0" | select IP).IP}},
@{N="Asset";E={(Get-Annotation -entity $VMHost.Name -CustomAttribute Asset |select value).value}},
@{N="Signature Applicativa";E={(Get-Annotation -entity $VMHost.Name -CustomAttribute SignatureApplicativa |select value).value}}
Inventory | Export-Csv -NoTypeInformation -Path ("C:\scripts\" + "Estrazione" + "_" + $((get-date).ToString("dd.MM.yyyy-HHmm"))+ ".csv" )
Try like this.
It uses the pipeline, no need for a ForEach loop
Get-VMHost |
Select-Object -Property Name,
@{N='vCenter';E={$_.Uid.Split(“:”)[0].Split(“@”)[1]}},
@{N="Modello";E={$_.ExtensionData.Hardware.Systeminfo.Model}},
@{N="IP MGT";E={(Get-VMHostNetworkAdapter -VMHost $_.Name -name "vmk0" | select IP).IP}},
@{N="Asset";E={(Get-Annotation -entity $_ -CustomAttribute Asset |select value).value}},
@{N="Signature Applicativa";E={(Get-Annotation -entity $_ -CustomAttribute SignatureApplicativa |select value).value}} |
Export-Csv -NoTypeInformation -Path ("C:\scripts\" + "Estrazione" + "_" + $((get-date).ToString("dd.MM.yyyy-HHmm"))+ ".csv" )
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this.
It uses the pipeline, no need for a ForEach loop
Get-VMHost |
Select-Object -Property Name,
@{N='vCenter';E={$_.Uid.Split(“:”)[0].Split(“@”)[1]}},
@{N="Modello";E={$_.ExtensionData.Hardware.Systeminfo.Model}},
@{N="IP MGT";E={(Get-VMHostNetworkAdapter -VMHost $_.Name -name "vmk0" | select IP).IP}},
@{N="Asset";E={(Get-Annotation -entity $_ -CustomAttribute Asset |select value).value}},
@{N="Signature Applicativa";E={(Get-Annotation -entity $_ -CustomAttribute SignatureApplicativa |select value).value}} |
Export-Csv -NoTypeInformation -Path ("C:\scripts\" + "Estrazione" + "_" + $((get-date).ToString("dd.MM.yyyy-HHmm"))+ ".csv" )
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference