Hi,
I am trying to write a script that will report on my Virtual Distributed Switches. My Script is as follows:
$reportcsv = @()
Get-VdsDistributedPortgroup | Sort Name -Descending |
ForEach-Object {
$vdsportgroup = $_
$vdsportgroupsec = $vdsportgroup | Get-VdsDVPortSecurityPolicy
$Report = "" | Select-Object "Port Group Name","Number of Ports","Port Binding","Virtual Switch","VLAN Id","VLAN Type","AllowPromiscuous","MAC Changes","Forged Transmits"
$Report."Port Group Name" = $vdsportgroup.Name
$Report."Number of Ports" = $vdsportgroup.NumPorts
$Report."Port Binding" = $vdsportgroup.PortBinding
$Report."Virtual Switch" = $vdsportgroup.VirtualSwitch
$Report."VLAN Id" = $vdsportgroup.VlanId
$Report."VLAN Type" = $vdsportgroup.VlanType
$Report."AllowPromiscuous" = $vdsportgroupsec.AllowPromiscuous
$Report."MAC Changes" = $vdsportgroupsec.MacChanges
$Report."Forged Transmits" = $vdsportgroupsec.AllowPromiscuous
$reportcsv += $Report
}
The script works, however when I view the contents of $reportcsv the values for AllowPromiscuous, MacChanges & ForgedTransmits shows up as VMware.VimAutomation.VdsComponent.Types.V1.BoolPolicy.
Does anyone have any suggestions?
Thanks
Frank
Those 3 properties are object themselves, that's why the object type is displayed.
You want the Value property from those objects.
Bwt, no need to use the unsupported fling for vDS, all info is available through regular PowerCLI cmdlets.
$reportcsv = @() Get-VirtualPortGroup -Distributed | Sort Name -Descending | ForEach-Object { $vdsportgroup = $_
$vdsportgroupsec = $vdsportgroup.ExtensionData.Config.DefaultPortConfig.SecurityPolicy
$Report = "" | Select-Object "Port Group Name","Number of Ports","Port Binding","Virtual Switch","VLAN Id","VLAN Type","AllowPromiscuous","MAC Changes","Forged Transmits"
$Report."Port Group Name" = $vdsportgroup.Name
$Report."Number of Ports" = $vdsportgroup.NumPorts
$Report."Port Binding" = $vdsportgroup.PortBinding
$Report."Virtual Switch" = $vdsportgroup.VirtualSwitch
$Report."VLAN Id" = $vdsportgroup.VlanId
$Report."VLAN Type" = $vdsportgroup.VlanType
$Report."AllowPromiscuous" = $vdsportgroupsec.AllowPromiscuous.Value
$Report."MAC Changes" = $vdsportgroupsec.MacChanges.Value
$Report."Forged Transmits" = $vdsportgroupsec.AllowPromiscuous.Value
$reportcsv += $Report
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Those 3 properties are object themselves, that's why the object type is displayed.
You want the Value property from those objects.
Bwt, no need to use the unsupported fling for vDS, all info is available through regular PowerCLI cmdlets.
$reportcsv = @() Get-VirtualPortGroup -Distributed | Sort Name -Descending | ForEach-Object { $vdsportgroup = $_
$vdsportgroupsec = $vdsportgroup.ExtensionData.Config.DefaultPortConfig.SecurityPolicy
$Report = "" | Select-Object "Port Group Name","Number of Ports","Port Binding","Virtual Switch","VLAN Id","VLAN Type","AllowPromiscuous","MAC Changes","Forged Transmits"
$Report."Port Group Name" = $vdsportgroup.Name
$Report."Number of Ports" = $vdsportgroup.NumPorts
$Report."Port Binding" = $vdsportgroup.PortBinding
$Report."Virtual Switch" = $vdsportgroup.VirtualSwitch
$Report."VLAN Id" = $vdsportgroup.VlanId
$Report."VLAN Type" = $vdsportgroup.VlanType
$Report."AllowPromiscuous" = $vdsportgroupsec.AllowPromiscuous.Value
$Report."MAC Changes" = $vdsportgroupsec.MacChanges.Value
$Report."Forged Transmits" = $vdsportgroupsec.AllowPromiscuous.Value
$reportcsv += $Report
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks.
That worked great!
I am having trouble getting the vlantype to display.
Any suggestions?
$reportcsv = @()
Get-VirtualPortGroup -Distributed | Sort Name -Descending | ForEach-Object {
$vdsportgroup = $_
$vdsportgroupvlan = $vdsportgroup.ExtensionData.Config.DefaultPortConfig.VLan
$vdsportgroupsec = $vdsportgroup.ExtensionData.Config.DefaultPortConfig.SecurityPolicy
$Report = "" | Select-Object "Port Group Name","Number of Ports","Port Binding","Virtual Switch","VLAN Id","VLAN Type","AllowPromiscuous","MAC Changes","Forged Transmits"
$Report."Port Group Name" = $vdsportgroup.Name
$Report."Number of Ports" = $vdsportgroup.NumPorts
$Report."Port Binding" = $vdsportgroup.PortBinding
$Report."Virtual Switch" = $vdsportgroup.VirtualSwitch
$Report."VLAN Id" = $vdsportgroupvlan.VlanId
$Report."VLAN Type" = $vdsportgroupvlan.VlanType
$Report."AllowPromiscuous" = $vdsportgroupsec.AllowPromiscuous.Value
$Report."MAC Changes" = $vdsportgroupsec.MacChanges.Value
$Report."Forged Transmits" = $vdsportgroupsec.AllowPromiscuous.Value
$reportcsv += $Report
}
The VlanId depends on the type of VLAN. That makes the scipt a bit more complex.
Try something like this
$reportcsv = @() Get-VirtualPortGroup -Distributed | Sort Name -Descending | ForEach-Object { $vdsportgroup = $_
$vdsportgroupsec = $vdsportgroup.ExtensionData.Config.DefaultPortConfig.SecurityPolicy
$vdsportgroupvlan = $vdsportgroup.ExtensionData.Config.DefaultPortConfig.Vlan
$Report = "" | Select-Object "Port Group Name","Number of Ports","Port Binding","Virtual Switch","VLAN Id","VLAN Type","AllowPromiscuous","MAC Changes","Forged Transmits"
$Report."Port Group Name" = $vdsportgroup.Name
$Report."Number of Ports" = $vdsportgroup.NumPorts
$Report."Port Binding" = $vdsportgroup.PortBinding
$Report."Virtual Switch" = $vdsportgroup.VirtualSwitch
if($vdsportgroupvlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){ $Report."VLAN Type" = "PVLan"
$Report."VLAN Id" = $vdsportgroupvlan.PvlanId
} elseif($vdsportgroupvlan -is [VMware.Vim.VmwareDistributedVirtualSwitchTrunkVlanSpec]){ $Report."VLAN Type" = "VLAN Trunking"
$Report."VLAN Id" = [string]::Join(',',($vdsportgroupvlan.VlanId | %{[string]$_.Start + "-" + [string]$_.End})) } else{ $Report."VLAN Type" = "None"
} $Report."AllowPromiscuous" = $vdsportgroupsec.AllowPromiscuous.Value
$Report."MAC Changes" = $vdsportgroupsec.MacChanges.Value
$Report."Forged Transmits" = $vdsportgroupsec.AllowPromiscuous.Value
$reportcsv += $Report
} $reportcsv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks.
I took it 1 step further. This seems to work pretty well.
$reportcsv = @()
Get-VirtualPortGroup -Distributed | Sort Name -Descending | ForEach-Object {
$vdsportgroup = $_
$vdsportgroupsec = $vdsportgroup.ExtensionData.Config.DefaultPortConfig.SecurityPolicy
$vdsportgroupvlan = $vdsportgroup.ExtensionData.Config.DefaultPortConfig.Vlan
$Report = "" | Select-Object "Port Group Name","Number of Ports","Port Binding","Virtual Switch","VLAN Id","VLAN Type","AllowPromiscuous","MAC Changes","Forged Transmits"
$Report."Port Group Name" = $vdsportgroup.Name
$Report."Number of Ports" = $vdsportgroup.NumPorts
$Report."Port Binding" = $vdsportgroup.PortBinding
$Report."Virtual Switch" = $vdsportgroup.VirtualSwitch
$Report."VLAN Type" = "Private VLAN"
$Report."VLAN Id" = $vdsportgroupvlan.PvlanId
}
elseif($vdsportgroupvlan -is ){
$Report."VLAN Type" = "VLAN Trunking"
$Report."VLAN Id" = ::Join(',',($vdsportgroupvlan.VlanId | %{[string]$_.Start + "-" + $_.End}))
}
elseif($vdsportgroupvlan -is ){
if($vdsportgroupvlan.vlanId -eq "0"){
$Report."VLAN Type" = "None"
$Report."VLAN Id" = $vdsportgroupvlan.vlanId
}
else{
$Report."VLAN Type" = "VLAN"
$Report."VLAN Id" = $vdsportgroupvlan.vlanId
}}
$Report."AllowPromiscuous" = $vdsportgroupsec.AllowPromiscuous.Value
$Report."MAC Changes" = $vdsportgroupsec.MacChanges.Value
$Report."Forged Transmits" = $vdsportgroupsec.AllowPromiscuous.Value
$reportcsv += $Report
LucD,
I tried to retrieve the vDS info but it throws an error in power cli 10.1.x version vSphere 6.5
PS C:\temp> .\vDS.ps1
WARNING: Parameter -Distributed is obsolete. To retrieve distributed portgroups, use Get-VDPortgroup cmdlet in the VDS
component.
Thanks
vmk
That is not an error, but a deprecation warning.
Meaning that the -Distributed parameter on the Get-VirtualPortgroup cmdlet might be removed in a future PowerCLI version.
See also the DisplayDeprecationWarnings parameter on the Set-PowerCLIConfiguration cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok i removed the parameter, but i cant find the csv ouput file ?
PS C:\temp> .\vDS.ps1
WARNING: The output of the command produced distributed virtual portgroup objects. This behavior is obsolete and may
change in the future. To retrieve distributed portgroups, use Get-VDPortgroup cmdlet in the VDS component. To retrieve
standard portgroups, use -Standard.
PS C:\temp>
thanks
vmk
Why did you remove the parameter?
Now you get VSS and VDS switches .
Not sure which version of the script in this thread you used, but the snippets do not contain an Export-Csv.
You will have to add one to get the results in a file.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Using VCenter VCSA 6.7 and ESXi 6.7 U1 and:
PowerCLI Version
----------------
VMware PowerCLI 11.0.0 build 10380590
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component PowerCLI Component 11.0 build 10335701
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.0 build 10336080
VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 11.0 build 10336077
VMware VimAutomation Cloud PowerCLI Component PowerCLI Component 11.0 build 10379994
The script did not work with the below error:
Invoke-Item : Cannot find path 'C:\Users\Admin\@{Port Group Name=dvSwitch-DVUplinks-9842; Number of Ports=20; Port Binding=Static; Virtual Switch=dvSwitch; VLAN Id=0-4094; VLAN Type=VLAN Trunking;
AllowPromiscuous=False; MAC Changes=False; Forged Transmits=False}' because it does not exist.
At line:28 char:1
+ Invoke-Item $reportcsv
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\Admin...ransmits=False}:String) [Invoke-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.InvokeItemCommand
It looks as if you're trying to "invoke" the array containing the results.
You will first have to save it to, for example a CSV, and then open the CSV with Invoke-Item.
Something like this
$reportcsv | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Invoke-Item -Path .\report.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference