1

Im trying to extract virtual network information for a VM using powershell, i tried using regular expression but for VM's with more than 1 NIC im unable to see output

Below is the output which i need..

PS C:\> get-vm sql.IAN01.Host | select -ExpandProperty virtualnetworkadapters | select virtualnetwork

VirtualNetwork
--------------
VirtualUplink
iSCSI1
iSCSI2
VirtualUplink

But when i try using regular expressions it does not give me an output, Network comes blank

PS C:\> Get-VM sql.IAN01.Host | Select @{Name="VMName";Expression={$_.name}},@{Name="Network
";Expression={@((get-vm $_.name | select -ExpandProperty virtualnetworkadapters).virtualnetwork)}}

VMName                                                      Network
------                                                      -------
sql.IADPSQLHST1N01.Hosting

Can anyone please help me out!!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
PowerShell
  • 1,991
  • 8
  • 35
  • 57

1 Answers1

1

Try this:

Get-VM sql.IAN01.Host | Select-Object @{Name="VMName";Expression={$_.name}},@{Name='VirtualNetwork';e={$_.VirtualNetworkAdapters | Foreach-Object{$_.VirtualNetwork}}}
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
  • Hi @Shay Levy can you help me with http://stackoverflow.com/questions/7525669/extracting-clustername-regularexpressions – PowerShell Sep 23 '11 at 07:31