quick question - basic script - combine two commands

Welcome Forums General PowerShell Q&A quick question - basic script - combine two commands

This topic contains 1 reply, has 2 voices, and was last updated by

5 years, 4 months ago.

  • Author
  • #15114

    Topics: 3
    Replies: 3
    Points: 0
    Rank: Member

    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

    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

    Topics: 1
    Replies: 51
    Points: 0
    Rank: Member

    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 }}

The topic ‘quick question - basic script - combine two commands’ is closed to new replies.