Created
January 23, 2017 15:08
-
-
Save Stephanevg/de8b4854a3bc803fa2365d6c7ca19ecf to your computer and use it in GitHub Desktop.
Uses NETSH to return the existing Windows firewall profiles. It returns all the elements in reworkable powershell objects (instead of plain text).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function Get-WindowsFireWallProfile { | |
| <# | |
| .Synopsis | |
| Get the windows firewall profile | |
| .DESCRIPTION | |
| Get the windows firewall profile based on netsh commands. Returns a workable powershell object. | |
| This function has been speceically developed to by pass the case where | |
| .EXAMPLE | |
| Get-WindowsFireWallProfile | |
| Returns all the existing profiles | |
| .EXAMPLE | |
| Get-WindowsFireWallProfile -Profile Current | |
| Returns the current applied firewall profile | |
| .EXAMPLE | |
| Get-WindowsFireWallProfile -Profile Domain | |
| Returns the domain profile | |
| .NOTES | |
| General notes | |
| #> | |
| Param( | |
| [ValidateSet('Public','Domain','Private','Current')]$Profile | |
| ) | |
| if (!($Profile)){ | |
| $AllProfiles = netsh advfirewall show allprofiles | |
| }else{ | |
| $ProfileType = $Profile + "profile" | |
| $AllProfiles = netsh advfirewall show $ProfileType | |
| } | |
| $return = @() | |
| $HAsh = [Ordered]@{} | |
| foreach ($property in $AllProfiles){ | |
| if ($property -match '(?<ProfileName>^\w+\s)Profile Settings:'){ | |
| $Hash.ProfileName = $Matches.ProfileName | |
| }Else{ | |
| if ($property -notmatch "----------------------------------------------------------------------" -and $property -notmatch '^\s+$'){ | |
| switch -Regex ($property){ | |
| '^State\s+(?<State>.*$)'{$Hash.State = $MAtches.State;Break} | |
| '^Firewall Policy\s+(?<FirewallPolicy>.*$)'{$Hash.FirewallPolicy = $MAtches.FirewallPolicy;Break} | |
| '^LocalFirewallRules\s+(?<LocalFirewallRules>.*$)'{$Hash.LocalFirewallRules = $MAtches.LocalFirewallRules;Break} | |
| '^LocalConSecRules\s+(?<LocalConSecRules>.*$)'{$Hash.LocalConSecRules = $MAtches.LocalConSecRules;Break} | |
| '^InboundUserNotification\s+(?<InboundUserNotification>.*$)'{$Hash.InboundUserNotification = $MAtches.InboundUserNotification;Break} | |
| '^RemoteManagement\s+(?<RemoteManagement>.*$)'{$Hash.RemoteManagement = $MAtches.RemoteManagement;Break} | |
| '^UnicastResponseToMulticast\s+(?<UnicastResponseToMulticast>.*$)'{$Hash.UnicastResponseToMulticast = $MAtches.UnicastResponseToMulticast;Break} | |
| '^LogAllowedConnections\s+(?<LogAllowedConnections>.*$)'{$Hash.LogAllowedConnections = $MAtches.LogAllowedConnections;Break} | |
| '^LogDroppedConnections\s+(?<LogDroppedConnections>.*$)'{$Hash.LogDroppedConnections = $MAtches.LogDroppedConnections;Break} | |
| '^FileName\s+(?<FileName>.*$)'{$Hash.FileName = $MAtches.FileName;Break} | |
| '^MaxFileSize\s+(?<MaxFileSize>.*$)'{$Hash.MaxFileSize = $MAtches.MaxFileSize;$obj = New-Object psobject -Property $Hash;$return += $obj;Break} | |
| default {Break} | |
| } | |
| } | |
| } | |
| } | |
| return $return | |
| } | |
| Get-WindowsFireWallProfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment