VMware Cloud Community
Fnilsen80
Enthusiast
Enthusiast
Jump to solution

Get command output to CSV/Table

Hi.

 

With this command;

get-vm | Get-NetworkAdapter
 
I get the output:
Fnilsen80_0-1656587679937.png

 

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....

Reply
0 Kudos
2 Solutions

Accepted Solutions
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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...

View solution in original post

ganapa2000
Hot Shot
Hot Shot
Jump to solution

Try with

@{N="Type";E={(Get-NetworkAdapter -VM $_).Type}},
@{N="NetworkName";E={(Get-NetworkAdapter -VM $_).NetworkName}}

View solution in original post

5 Replies
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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...

Fnilsen80
Enthusiast
Enthusiast
Jump to solution

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?

 

Connect-VIserver vcenter.test.net -User administrator@vsphere.local -Password
Get-VM |
select Name,
    NumCpu, MemoryGB,
    @{n="HardDiskSizeGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
    ProvisionedSpaceGB, UsedSpaceGB,
    @{N="Datastore";E={$_.ExtensionData.Config.DatastoreUrl.Name}},
    @{N="Configured GuestOS";E={$_.ExtensionData.Config.GuestFullName}},
    @{N="Running OS";E={$_.Guest.OsFullName}},
    @{N=”Network”;E={$_.Guest.Nics[0]}},
    @{N="vCenter";E={'pscse-vc1.mgmt.cgipsc.com'}},
    @{Name=’Cluster’;Expression={$_.VMHost.Parent}},
    VMHost, ResourcePool, HardwareVersion, PowerState,
    @{N="Status";E={$_.ExtensionData.guest.guestState}},
    @{N="Up Time";E={$Timespan = New-Timespan -Seconds (Get-Stat -Entity $_.Name -Stat sys.uptime.latest -Realtime -MaxSamples 1).Value
      "" + $Timespan.Days + " Days, "+ $Timespan.Hours + " Hours, " +$Timespan.Minutes + " Minutes"}},
    @{N="IPAddress";E={$_.Guest.IPAddress[0]}},
    CreateDate, MemoryHotAddEnabled, CpuHotAddEnabled,
    @{N="Tools Installed";E={$_.Guest.ToolsVersion -ne ""}},
    @{N="Tools Version";E={if($_.Guest.ToolsVersion -ne ""){$_.Guest.ToolsVersion}}},
    @{N="Tools Status";E={$_.ExtensionData.Guest.ToolsStatus}},
    Notes
     |
Export-Csv "C:\Reporting\VMreport3_$((Get-Date).ToString("yyyy-MM-dd")).csv" -NoTypeInformation

get-vm | Get-NetworkAdapter | Select @{N="VM";E={$_.Parent.Name}}, Type, NetworkName
Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Try with

@{N="Type";E={(Get-NetworkAdapter -VM $_).Type}},
@{N="NetworkName";E={(Get-NetworkAdapter -VM $_).NetworkName}}

Fnilsen80
Enthusiast
Enthusiast
Jump to solution

Fantastic. Thank you 🙂

/f

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos