-
-
Save p0w3rsh3ll/942bce3bdf8541f15050 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
Function Get-TargetResource { | |
[CmdletBinding()] | |
[OutputType([Hashtable])] | |
Param ( | |
[parameter(Mandatory)] | |
[ValidateSet('Domain','Public','Private')] | |
[String]$Name, | |
[parameter(Mandatory)] | |
[ValidateSet('True','False','NotConfigured')] | |
[String]$Enabled, | |
[parameter(Mandatory)] | |
[ValidateSet('Allow','Block','NotConfigured')] | |
[String]$DefaultInboundAction, | |
[parameter(Mandatory)] | |
[ValidateSet('Allow','Block','NotConfigured')] | |
[String]$DefaultOutboundAction | |
) | |
$p = Get-NetFirewallProfile -Name $Name | |
@{ | |
Name = $p.Name ; | |
Enabled = $p.Enabled ; | |
DefaultInboundAction = $p.DefaultInboundAction ; | |
DefaultOutboundAction = $p.DefaultOutboundAction ; | |
} | |
} | |
Function Set-TargetResource { | |
[CmdletBinding()] | |
Param ( | |
[parameter(Mandatory)] | |
[ValidateSet('Domain','Public','Private')] | |
[String]$Name, | |
[parameter(Mandatory)] | |
[ValidateSet('True','False','NotConfigured')] | |
[String]$Enabled, | |
[parameter(Mandatory)] | |
[ValidateSet('Allow','Block','NotConfigured')] | |
[String]$DefaultInboundAction, | |
[parameter(Mandatory)] | |
[ValidateSet('Allow','Block','NotConfigured')] | |
[String]$DefaultOutboundAction | |
) | |
Write-Verbose "Configuring Firewall Profile $($Name) to $($Enabled)" | |
Write-Verbose "Setting Firewall Profile $($Name) DefaultInboundAction to $($DefaultInboundAction)" | |
Write-Verbose "Setting Firewall Profile $($Name) DefaultOutboundAction to $($DefaultOutboundAction)" | |
Set-NetFirewallProfile @PSBoundParameters | |
} | |
Function Test-TargetResource { | |
[CmdletBinding()] | |
[OutputType([System.Boolean])] | |
Param ( | |
[parameter(Mandatory)] | |
[ValidateSet('Domain','Public','Private')] | |
[String]$Name, | |
[parameter(Mandatory)] | |
[ValidateSet('True','False','NotConfigured')] | |
[String]$Enabled, | |
[parameter(Mandatory)] | |
[ValidateSet('Allow','Block','NotConfigured')] | |
[String]$DefaultInboundAction, | |
[parameter(Mandatory)] | |
[ValidateSet('Allow','Block','NotConfigured')] | |
[String]$DefaultOutboundAction | |
) | |
$current = Get-TargetResource @PSBoundParameters | |
$result = $true | |
if ($current.Enabled -ne $Enabled) { | |
$result = $false | |
} | |
if ($current.DefaultInboundAction -ne $DefaultInboundAction) { | |
$result = $false | |
} | |
if ($current.DefaultOutboundAction -ne $DefaultOutboundAction) { | |
$result = $false | |
} | |
$result | |
} | |
Export-ModuleMember -Function *-TargetResource |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment