Skip to content

Instantly share code, notes, and snippets.

@alexandrinos
Created December 25, 2015 12:26
Show Gist options
  • Save alexandrinos/709bb4deda7a99f05c73 to your computer and use it in GitHub Desktop.
Save alexandrinos/709bb4deda7a99f05c73 to your computer and use it in GitHub Desktop.
Firewall info -open ports etc with Powershell
Function Get-EnabledRules
{
Param($profile)
$rules = (New-Object -comObject HNetCfg.FwPolicy2).rules
$rules = $rules | where-object {$_.Enabled -eq $true}
$rules = $rules | where-object {$_.Profiles -bAND $profile}
$rules
}
$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
$connections = $networkListManager.GetNetworkConnections()
[int[] ] $connTypes = @()
$connTypes = ($connections | % {$_.GetNetwork().GetCategory()})
#$connTypes += 1
Write-Host $connTypes
$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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment