Automation

 View Only
  • 1.  Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 05:42 PM

    Hello All,

    Sorry to do this but I'm in kind of a hurry. I know I need to read the manual and I plan to do so very soon!!

    I'm trying to build a table or create output that displays the VM name and the NetworkName. I don't know how to make the output show both. I put together the command below, but this only displays the NetworkName. I've tried various things, but I can't get both items to show up...

    Can anyone help me out? Thanks!!!!

    Get-Cluster DEV | Get-VM | Get-NetworkAdapter | Select-Object -Property 'NetworkName'



  • 2.  RE: Creating Tables using Piped Cmdlets
    Best Answer

    Posted Mar 09, 2012 05:45 PM

    Try something like this

    Get-Cluster DEV | Get-VM | 
    Select Name, @{N="NIC";E={$_ | Get-NetworkAdapter | %{$_.NetworkName}}}

    If you have more than 1 NIC on a VM, you can do

    Get-Cluster DEV | Get-VM | 
    Select Name, @{N="NIC";E={[string]::Join(',',($_ | Get-NetworkAdapter | %{$_.NetworkName}))}}


  • 3.  RE: Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 06:13 PM

    Thanks LucD- I'm getting this returned to me (using PowerGUI):


    Missing '=' operator after key in hash literal.At line: 4 char: 26

    It's telling me there's something wrong around here "E{$"



  • 4.  RE: Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 06:27 PM

    My mistake, typo. It's corrected



  • 5.  RE: Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 06:40 PM

    Ok, this only displays the VM names. Doesn't show the NetworkNames.



  • 6.  RE: Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 06:58 PM

    I think it's time I call it a day, another typo.

    It's corrected now



  • 7.  RE: Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 07:41 PM

    Thanks Luc. That works. Oddly it returns the right data from Powercli, but if I run it in PowerGUI I only get the VM names back. No NetworkNames.



  • 8.  RE: Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 07:52 PM

    Are you running the latest version of PowerGui ?



  • 9.  RE: Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 08:46 PM

    Yep- latest PowerGUI, and I just upgraded my PowerCLI too. Same result in PowerGUI. Only VM names.



  • 10.  RE: Creating Tables using Piped Cmdlets

    Posted Mar 09, 2012 09:13 PM

    Must be a PowerGui problem then.

    I'll have to admit I'm not well versed in PowerGui, but perhaps you could raise the question in the PowerGui forum.