For some reason this is only working on port groups on vswitch0.
Foreach ($vh01 in (Get-View -ViewType HostSystem -Filter @{"Name" = "esx1.domain.com"})){
$NetworkSystem = Get-View $vh01.ConfigManager.NetworkSystem
Foreach ($pg in $NetworkSystem.Networkconfig.PortGroup){
If($pg.spec.Name -like "VM*"){
Write $pg.spec.Name
$pg.spec.policy.security.allowPromiscuous=$true
$NetworkSystem.UpdatePortgroup($pg.spec.name,$pg.spec)
}
}
}
The rest get this error:
Property 'allowPromiscuous' cannot be found on this object; make sure it exists
and is settable.
At H:\Scripts\pg-security-test1.ps1:44 char:37
+ $pgspec.policy.security. <<<< allowPromiscuous=$true
+ CategoryInfo : InvalidOperation: (allowPromiscuous:String) [],
RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound