PowerCLI

 View Only
  • 1.  Script to list VM Network Adapter Type, exporting issue

    Posted Mar 22, 2012 07:40 PM

    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



  • 2.  RE: Script to list VM Network Adapter Type, exporting issue

    Posted Mar 22, 2012 07:46 PM

    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
     


  • 3.  RE: Script to list VM Network Adapter Type, exporting issue

    Posted Mar 22, 2012 07:56 PM

    Wow, thank you for the prompt reply!  :smileyhappy:



  • 4.  RE: Script to list VM Network Adapter Type, exporting issue

    Posted Mar 23, 2012 09:36 PM

    LucD,

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

    thanks

    vmguy



  • 5.  RE: Script to list VM Network Adapter Type, exporting issue

    Posted Mar 23, 2012 10:14 PM

    Sure, take out the Where-clause.



  • 6.  RE: Script to list VM Network Adapter Type, exporting issue

    Posted Apr 04, 2012 05:19 PM

    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.



  • 7.  RE: Script to list VM Network Adapter Type, exporting issue

    Posted Apr 04, 2012 08:16 PM

    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


  • 8.  RE: Script to list VM Network Adapter Type, exporting issue

    Posted Apr 05, 2012 03:28 PM

    Thanks for your reply Luc.

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



  • 9.  RE: Script to list VM Network Adapter Type, exporting issue

    Posted Oct 03, 2016 04:56 PM

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