Hi.
With this command;
Can someone please help me with a script that adds a VM name column to the table and exports it to a CSV with the columns; vmname, name, type, networkname etc....
you can try as below
get-vm POCLTRAINING10 | Get-NetworkAdapter | Select @{N="VM";E={$_.Parent.Name}}, Name, Type, NetworkName, MacAddress, WakeOnLanEnabled | Export-Csv -Path "D:\nw.csv" -NoTypeInformation -UseCulture
you can always search the community to get the answers.
Reference : https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Get-VM-Get-NetworkAdapter-Select-Objec...
Try with
@{N="Type";E={(Get-NetworkAdapter -VM $_).Type}},
@{N="NetworkName";E={(Get-NetworkAdapter -VM $_).NetworkName}}
you can try as below
get-vm POCLTRAINING10 | Get-NetworkAdapter | Select @{N="VM";E={$_.Parent.Name}}, Name, Type, NetworkName, MacAddress, WakeOnLanEnabled | Export-Csv -Path "D:\nw.csv" -NoTypeInformation -UseCulture
you can always search the community to get the answers.
Reference : https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Get-VM-Get-NetworkAdapter-Select-Objec...
Thanks.
My searches aren't always good...
My next question then, is how I add this line (in red at the bottom) to my existing script, so that "Type" and "NetworkName" from the "Get-NetworkAdapter" becomes to additional columns in the exported CSV?
Try with
@{N="Type";E={(Get-NetworkAdapter -VM $_).Type}},
@{N="NetworkName";E={(Get-NetworkAdapter -VM $_).NetworkName}}
Fantastic. Thank you 🙂
/f
Just a little remark, when a VM has more than 1 vNIC this will not work.
See the -join operator in the post referred to earlier.
That will fix that situation.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference