There are two values ββthat a COM object controls for a firewall. 0 represents a network of domains, and 1 represents a standard network. There are no (in this API) differences between these public and private profiles.
You can replace the last section
$fwMgr = New-Object -ComObject HNetCfg.FwMgr $profile = $fwMgr.LocalPolicy.CurrentProfile $profile.GloballyOpenPorts.Add($port)
with
$Profiles = @{ NET_FW_PROFILE_DOMAIN = 0 NET_FW_PROFILE_STANDARD = 1 } $fwMgr = New-Object -ComObject HNetCfg.FwMgr $profile.GloballyOpenPorts.Add($port) foreach ($ProfileKey in $Profiles.Keys) { $Profile = $fwMgr.LocalPolicy.GetProfileByType($profiles[$ProfileKey]) $Profile.GloballyOpenPorts.Add($Port) }
source share