VMware Cloud Community
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

Output All VM Names and MAC Addresses from Multiple vCenters to CSV

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

Outstanding work as always Luc!

Reply
0 Kudos