Hi,
I'm looking to generate a query that queries multiple vCenters and outputs a CSV in the following format:
vCenter Name | Cluster Name | VM Name | VM MAC Address
My script draft is as follows, but I don't fully understand how the Select statement is formated.
$MAC_Address_Report = foreach($vc in $global:DefaultVIServers){
$vCList = $vc
$vCCluster = get-Cluster
$vmList = get-VM
$MAC_Addr = get-VM PNA* | Get-NetworkAdapter
Select @{N="vCenter";E={$vCList.Name}} @{N="Cluster";E={$vCCluster.Name}}, @{N="VM Name"; E={$vmList.Name}}, @{N="MAC Address";E={$MAC_Addr.MacAddress}}
}
$MAC_Address_Report| Export-Csv C:\Scripts\VM_MAC_Address_Inventory.csv
Try like this.
It uses the pipeline, and a PipelineVariable, to get to the NICs, and then uses calculated properties to select the desired fields.
Get-Cluster -Server $global:DefaultVIServers -PipelineVariable cluster |
Get-VM |
Get-NetworkAdapter |
Select @{N='VC';E={$_.Uid.Split('@')[1].Split(':')[0]}},
@{N='Cluster';E={$cluster.Name}},
@{N='VM';E={$_.Parent.Name}},
@{N='NIC';E={$_.Name}},
@{N='Mac';E={$_.MacAddress}} |
Export-Csv C:\Scripts\VM_MAC_Address_Inventory.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this.
It uses the pipeline, and a PipelineVariable, to get to the NICs, and then uses calculated properties to select the desired fields.
Get-Cluster -Server $global:DefaultVIServers -PipelineVariable cluster |
Get-VM |
Get-NetworkAdapter |
Select @{N='VC';E={$_.Uid.Split('@')[1].Split(':')[0]}},
@{N='Cluster';E={$cluster.Name}},
@{N='VM';E={$_.Parent.Name}},
@{N='NIC';E={$_.Name}},
@{N='Mac';E={$_.MacAddress}} |
Export-Csv C:\Scripts\VM_MAC_Address_Inventory.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Outstanding work as always Luc!