How to change this powershell to one line?

Discussion in 'Programming & Software Development' started by Multiplexer, Oct 25, 2020.

  1. Multiplexer

    Multiplexer Member

    Joined:
    Feb 26, 2002
    Messages:
    2,120
    Location:
    Home
    Found a good script at from vmware community forum but I am unable to make it run if I change it to one line

    The following code works
    Code:
    Get-VM | Get-NetworkAdapter | Select-Object @{N="VM";E={$_.Parent.Name}}, @{N="NIC";E={$_.Name}}, @{N="Network";E={$_.NetworkName}}, MacAddress, @{N='IP';E={$vNIc = $_
    (($_.Parent.ExtensionData.Guest.Net | where { $_.MacAddress -eq $vNIc.MacAddress }).IPAddress -notmatch ':')-join '|'}}
    When change to one line then it stop working. Why and how do I fix it?
     
    Last edited: Oct 25, 2020
  2. Hookimus

    Hookimus Member

    Joined:
    Jan 11, 2016
    Messages:
    65
    Location:
    Sydney
    I think this should work? (not tested tho)
    Get-VM | Get-NetworkAdapter | Select-Object @{N="VM";E={$_.Parent.Name}}, @{N="NIC";E={$_.Name}}, @{N="Network";E={$_.NetworkName}}, MacAddress, @{N='IP';E={$vNIc = $_ ; (($_.Parent.ExtensionData.Guest.Net | where { $_.MacAddress -eq $vNIc.MacAddress }).IPAddress -notmatch ':')-join '|'}}

    the semi-colon can be used as a statement separator (or new line)
     
    Multiplexer likes this.

Share This Page

Advertisement: