andreasbrunner
Contributor
Contributor

Help needed with report creation (vm, portgroup, vlanid)

Jump to solution

Hello,

I need some help.

I want to create a report that shows the following:

Report Portgroup (Networkname), VLANID, VM (Parent), Connectionstate


Portgroup, VM and Connectionstate are reported by:

$pg1 = Get-VM -DistributedSwitch dvSwitch1| Get-NetworkAdapter
$pg1 |  select Networkname, Parent, connectionstate

The VLANID is reported by:


$VMs = Get-VM -DistributedSwitch dvSwitch1
$pg2 = $vms | Get-VirtualPortGroup

$vlanid = $pg2 | select name, @{N="Vlanid";E={$vlanid.extensiondata.Config.DefaultPortConfig.Vlan.VlanId}}

The question is how to combine these lines and to be able add the vlanid to the report?

I tried something like:

Add-Member -InputObject $pg1 -Name ("Vlanid" +$_ ) -MemberType NoteProperty -Value $vlanid.extensiondata.Config.DefaultPortConfig.Vlan.VlanId

Thanks for helping.

regards

Andreas

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try it like this

foreach($vm in Get-VM -DistributedSwitch dvSw1){
    $nic = Get-NetworkAdapter -VM $vm
    $vm | Select Name,         @{N="NetworkName";E={$nic.NetworkName}},         @{N="ConnectionState";E={$nic.ConnectionState.Connected}},         @{N="VlanId";E={(Get-VirtualPortGroup -VM $vm -Distributed).Extensiondata.Config.DefaultPortConfig.Vlan.VlanId}} }


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
andreasbrunner
Contributor
Contributor

I also tried similiar as shown in this thread


http://communities.vmware.com/thread/298129?start=0&tstart=30

But in this case I do not receive the vlanid or the portgroupname

Get-VM -DistributedSwitch dvSwitch1 | Select Name,
    @{N="Portgroup";E={[string]::Join(',',($_.Guest.Nics | %{$_.NetworkName}))}},
    @{N="VLANid";E={(Get-VirtualPortGroup -Name $_.NetworkName -VM $_).VLanId}} |
Export-Csv "C:\NIC-info.csv" -NoTypeInformation
0 Kudos
LucD
Leadership
Leadership

Try it like this

foreach($vm in Get-VM -DistributedSwitch dvSw1){
    $nic = Get-NetworkAdapter -VM $vm
    $vm | Select Name,         @{N="NetworkName";E={$nic.NetworkName}},         @{N="ConnectionState";E={$nic.ConnectionState.Connected}},         @{N="VlanId";E={(Get-VirtualPortGroup -VM $vm -Distributed).Extensiondata.Config.DefaultPortConfig.Vlan.VlanId}} }


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
andreasbrunner
Contributor
Contributor

I really learned something today. Many thanks. It works as wished.

regards

Andreas

0 Kudos