I'm seeing some unexpected behaviour when I attempt to break apart my script that was listing all the port groups on dvSwitches at the datacenter level. I attempted to construct a loop around the script that would perform an action on each specific dvSwitch vs. conglomerating all port groups together (initial script works fine, just the output is a little messy). What's happening now is it seems to be properly running through each dvSwitch and creating output for each switch, but the output is the same for each switch. So clearly I've got some sort of logic error - need to reinitialize the array at the end of the loop or something like that.
One other bit of housekeeping I've successfully addressed before but now isn't working is trying to eliminate specific array members - in this case, the dvUplinks output (I'm only interested in Portgroups). I used a select-string - notmatch in previous code but that's not working here (which you'll see commented out below). I tried a few iterations of the Where-object -notcontains methods a fellow here uses with no success: http://www.powershellcommunity.org/Forums/tabid/54/aft/3993/Default.aspx
$dvSwitch = Get-VirtualSwitch -Distributed -Datacenter blah
foreach ($dvs in $dvSwitch) {
Get-VirtualPortGroup |`
Select Name, @{N="VLANId";E={$_.Extensiondata.Config.DefaultPortConfig.Vlan.VlanId}}, NumPorts |`
# select-string -notmatch "dvSwitch-DVUplinks" |`
export-csv d:\scripts\portgroups\$dvs.csv
}
Any advice is (as always) greatly appreciated.
Dave
You have to specify for which switch you want the portgroups
$dvSwitch = Get-VirtualSwitch -Distributed -Datacenter blah
foreach ($dvs in $dvSwitch) { Get-VirtualPortGroup -VirtualSwitch $dvs | Select Name, @{N="VLANId";E={$_.Extensiondata.Config.DefaultPortConfig.Vlan.VlanId}}, NumPorts | export-csv d:\scripts\portgroups\$dvs.csv
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You have to specify for which switch you want the portgroups
$dvSwitch = Get-VirtualSwitch -Distributed -Datacenter blah
foreach ($dvs in $dvSwitch) { Get-VirtualPortGroup -VirtualSwitch $dvs | Select Name, @{N="VLANId";E={$_.Extensiondata.Config.DefaultPortConfig.Vlan.VlanId}}, NumPorts | export-csv d:\scripts\portgroups\$dvs.csv
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference