Hay there!
I'm trying to export some data from my VC to CSV and I got stuck mid-way.
What I need is a CSV file with these headers: "VM_Name", "VM_Datastore", "VM_NIC0_MAC", "VM_NIC1_MAC" .
All the VM's are in the same cluster, and with a name containing the pattern "*\(*\)" . (all VM's with a vCD name extension).
So far I managed to get only the names in the output, and I'm having a hard time getting the rest of the information out.
This is what I did:
Get-Cluster "QA" | get-vm | Select-String -Pattern "\(*\)" | Select-Object Line | Export-Csv C:\Export.csv
As you can see, It's far from even coming close to what I need, so any help would be much appreciated...
Get-Cluster "QA" | get-vm | Select-String -Pattern "\(*\)" | Select-Object Line | Export-Csv C:\Export.csv
You can use a Where-clause the filter out the VMs that you want, then a Select to retrieve the required properties.
Try like this
Get-Cluster "QA" |
Get-VM |
Where {$_.Name -match "\(*\)"} |
Select Name,
@{N="Datastore";E={(Get-View $_.DatastoreIdList | %{$_.Name}) -Join ','}},
@{N="MAC0";E={$_.NetworkAdapters[0].MacAddress}},
@{N="MAC1";E={$_.NetworkAdapters[1].MacAddress}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use a Where-clause the filter out the VMs that you want, then a Select to retrieve the required properties.
Try like this
Get-Cluster "QA" |
Get-VM |
Where {$_.Name -match "\(*\)"} |
Select Name,
@{N="Datastore";E={(Get-View $_.DatastoreIdList | %{$_.Name}) -Join ','}},
@{N="MAC0";E={$_.NetworkAdapters[0].MacAddress}},
@{N="MAC1";E={$_.NetworkAdapters[1].MacAddress}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, that is exactly what I needed.
Thanks mate!