-
-
Save p0w3rsh3ll/d6b29c70325d80123552 to your computer and use it in GitHub Desktop.
This file contains 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
Enum Enabled { | |
True | |
False | |
} | |
Enum Action { | |
Allow | |
Block | |
NotConfigured | |
} | |
[DscResource()] | |
class ClassFirewallProfile { | |
[DscProperty(Key)] | |
[string]$Name | |
[DscProperty(Mandatory)] | |
[Enabled]$Enabled | |
[DscProperty(Mandatory)] | |
[Action]$DefaultInboundAction | |
[DscProperty(Mandatory)] | |
[Action]$DefaultOutboundAction | |
[ClassFirewallProfile] Get() { | |
$p = Get-NetFirewallProfile -Name $this.Name -ErrorAction SilentlyContinue | |
$r = @{ | |
Name = [String]$p.Name | |
Enabled = [String]$p.Enabled | |
DefaultInboundAction = [String]$p.DefaultInboundAction | |
DefaultOutboundAction = [String]$p.DefaultOutboundAction | |
} | |
return $r | |
} | |
[void] Set() { | |
Write-verbose "Changing firewall profile $($this.Name)" | |
Set-NetFirewallProfile -Enabled "$($this.Enabled)"` | |
-Name "$($this.Name)"` | |
-DefaultInboundAction "$($this.DefaultInboundAction)"` | |
-DefaultOutboundAction "$($this.DefaultOutboundAction)" | |
Write-Verbose -Message "Successfully set the firewall profile $($this.Name)" | |
} | |
[bool] Test() { | |
$p = Get-NetFirewallProfile -Name $this.Name -ErrorAction SilentlyContinue | |
$bool = $true | |
if(($this.Enabled) -ne ($p.Enabled).ToString()) { | |
Write-Verbose "Firewall profile $($this.Name) is not $($this.Enabled)" | |
$bool = $false | |
} | |
if($this.DefaultInboundAction -ne ($p.DefaultInboundAction).ToString()) { | |
Write-Verbose ("Firewall profile {0} DefaultInboundAction is not {1} but is set to {2}" -f $($this.Name), | |
$($this.DefaultInboundAction),$($p.DefaultInboundAction)) | |
$bool = $false | |
} | |
if($this.DefaultOutboundAction -ne ($p.DefaultOutboundAction).ToString()) { | |
Write-Verbose ("Firewall profile {0} DefaultOutboundAction is not {1} but is set to {2}" -f $($this.Name), | |
$($this.DefaultOutboundAction),$($p.DefaultOutboundAction)) | |
$bool = $false | |
} | |
return $bool | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment