VMware Cloud Community
BenLiebowitz
Expert
Expert

Script to list VM Network Adapter Type, exporting issue

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

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.
8 Replies
LucD
Leadership
Leadership

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

BenLiebowitz
Expert
Expert

Wow, thank you for the prompt reply!  Smiley Happy

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.
Reply
0 Kudos
vmhyperv
Contributor
Contributor

LucD,

   Is it possible to pull all the network adaptor  type rather than "VMNXT3" specific.?

thanks

vmguy

Reply
0 Kudos
LucD
Leadership
Leadership

Sure, take out the Where-clause.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
kjthacker
Commander
Commander

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.

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
kjthacker
Commander
Commander

Thanks for your reply Luc.

I must have been doing something wrong yesterday. Today, the command works fine.

Reply
0 Kudos
ThomasLooper
Contributor
Contributor

Hi Ben! I know this is an old post but I found it useful for a script I am testing. Thanks!

Reply
0 Kudos