1Function Get-EnabledRules
2{
3 Param($profile)
4 $rules = (New-Object -comObject HNetCfg.FwPolicy2).rules
5 $rules = $rules | where-object {$_.Enabled -eq $true}
6 $rules = $rules | where-object {$_.Profiles -bAND $profile}
7 $rules
8}
9
10$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
11 $connections = $networkListManager.GetNetworkConnections()
12[int[] ] $connTypes = @()
13$connTypes = ($connections | % {$_.GetNetwork().GetCategory()})
14#$connTypes += 1
15Write-Host $connTypes
16
17$connTypes | ForEach-Object {Get-EnabledRules -profile $_ | sort localports,Protocol | format-table -wrap -autosize -property Name, @{Label="Action"; expression={$_.action}}, @{Label="Protocol"; expression={$_.protocol}}, localPorts,applicationname}
18