Hi,
I wrote a PowerCLI script to list network adapters that are NOT VMXNet3. The syntax works fine in PowerCLI however the Export-csv command is creating a 0k csv file.
Get-VM | Get-NetworkAdapter | Where-object {$_.Type -ne "Vmxnet3"} | foreach ($_) {Write-Host $_.Parent.Name "("$_.Name") type:" $_.Type} | export-Csv c:\Network_Interface.csv -NoTypeInformation
Results look like:
VM1 ( Network adapter 1 ) type: Flexible
VM2 ( Network adapter 1 ) type: e1000
Any help would be appreciated.
- Ben
To export you better use the Select-Object cmdlet.
Like this
Get-VM | Get-NetworkAdapter | Where-object {$_.Type -ne "Vmxnet3"} | Select @{N="VM";E={$_.Parent.Name}},Name,Type | export-Csv c:\Network_Interface.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wow, thank you for the prompt reply!
LucD,
Is it possible to pull all the network adaptor type rather than "VMNXT3" specific.?
thanks
vmguy
Sure, take out the Where-clause.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
I copied and pasted the script into Notepad and removed the "Where" and "Export-Csv" lines so that I could simplify the script. Turns out I can get the script to echo a VM name under the "VM" column. Do you have any thoughts on what I might be doing wrong? I'm using PowerCLI 5.0, build 435427.
Get-VM | Get-NetworkAdapter | Select @{N="VM";E={$_.Parent.Name}},Name,Type,WakeOnLan
What am I missing?
Thanks.
Is this from the PowerCLI prompt or a GUI ?
Could it be that the console width is too small ?
Try
Get-VM | Get-NetworkAdapter | Select @{N="VM";E={$_.Parent.Name}},Name,Type,WakeOnLan | fl
This will display the requested properties in a list format (Format-List).
Or you could diminish the width of the columns
Get-VM | Get-NetworkAdapter | Select @{N="VM";E={$_.Parent.Name}},Name,Type,WakeOnLan | ft -Autosize
And you could also try
Get-VM | Get-NetworkAdapter | Select @{N="VM";E={$_.Parent.Name}},Name,Type,WakeOnLan | Out-Default
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your reply Luc.
I must have been doing something wrong yesterday. Today, the command works fine.
Hi Ben! I know this is an old post but I found it useful for a script I am testing. Thanks!