PowerShell
PowerShell

Reputation: 2081

Unable to extract VirtualNetwork Name using SCVMM powershell modules

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

Upvotes: 1

Views: 165

Answers (1)

Shay Levy
Shay Levy

Reputation: 126902

Try this:

Get-VM sql.IAN01.Host | Select-Object @{Name="VMName";Expression={$_.name}},@{Name='VirtualNetwork';e={$_.VirtualNetworkAdapters | Foreach-Object{$_.VirtualNetwork}}}

Upvotes: 1

Related Questions