quick question - basic script - combine two commands

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Robert Westerlund Robert Westerlund 2 years, 7 months ago.

  • Author
    Posts
  • #15114
    Profile photo of Jeremy Anderson
    Jeremy Anderson
    Participant

    All, new at all the scripting things and I am missing a basic step I hope you can clue me in on. I am using VmWare Powercli, but I am 99% sure this is basic Powershell that applies to all users.

    So this line :

    get-cluster "Cluster" | Get-VM | select-object name, vmhost, folder

    Returns me a nice little output of the data I want, like this

    Name VMHost Folder
    —- —— ——
    P-SPAPP02 esx0315-mgmt Sharepoint
    p-netops02 esx0315-mgmt NetOps
    P-LyncSQL01 esx0315-mgmt Lync

    And this returns some nice, pretty information as well.

    get-cluster "Cluster" | Get-VM | get-networkadapter | select-object networkname

    NetworkName
    ———–
    Corporate Network
    VM Production
    MSCS Private Network

    What is the easy, simple way to combine the two commandlets to that my final output is this:

    Name VMHost Folder NetworkName
    —- —— —— ———–
    P-SPAPP02 esx0315-mgmt Sharepoint Corporate Network
    p-netops02 esx0315-mgmt NetOps VM Production
    P-LyncSQL01 esx0315-mgmt Lync MSCS Private Network

    Thanks for your help....

  • #15115
    Profile photo of Robert Westerlund
    Robert Westerlund
    Participant

    This is written without being able to test it, so there might of course be a spelling error or two, but I believe something along the lines of the following should work:

    Get-Cluster "Cluster" | Get-VM | Select Name, VMHost, Folder, @{ Name= 'NetworkName', Expression = { $_ | Get-NetworkAdapter | Select -Expand NetworkName }}

You must be logged in to reply to this topic.