Skip to content

Instantly share code, notes, and snippets.

@p0w3rsh3ll
Created March 26, 2016 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p0w3rsh3ll/942bce3bdf8541f15050 to your computer and use it in GitHub Desktop.
Save p0w3rsh3ll/942bce3bdf8541f15050 to your computer and use it in GitHub Desktop.
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