VMware Cloud Community
ivanunnio
Enthusiast
Enthusiast
Jump to solution

How to Export one list of more vCenter and asset,ip,model,signature for farm.

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" )

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

1 Reply
LucD
Leadership
Leadership
Jump to solution

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