Hi I need to gather the VLAN information against my environment to check to see if VLAN's have been configured
$report = @()
foreach($esx in Get-VMHost){
$vms = Get-VM -Location $esx
foreach($pg in (Get-VirtualPortGroup -VMHost $esx)){
$vms | where {$_.Guest.Nics | where {$_.NetworkName -eq $pg.Name}} | foreach {
$Report += New-Object PSObject -Property @{
"Host"=$esx.Name
"VM"=$_.Name
"VLAN ID"=$pg.VlanId
"Port Group"=$pg.Name
"IP"=[string]::Join(',',($_.Guest.Nics | where {$_.NetworkName -eq $pg.Name} | %{$_.IPAddress | %{$_}}))
}
}
}
}
$report | Export-Csv "C:\testVLAN-report.csv" -NoTypeInformation -UseCulture
this gathers most of the information but isn't pull back the VLAN ID? anybody know why?
Are the ones that are missing by any chance portgroups on dvSwitches ?
Seems to be ok for portgroups on regular vSwitches.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes Luc
you are correct it work on standard vSwitch but not on dvSwitches
I know the is a new cmdlet get-VDPortGroup which gathers the dvSwtich Vlan Configuration but i would like to be able to have both in the report
Have a look at 1. Re: Script to obtain all portgroups in a Datacenter and their VLAN ID
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference