-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new docs and new add-functions for pipeline and progress bars
- Loading branch information
1 parent
a710225
commit 7d0edbb
Showing
16 changed files
with
685 additions
and
80 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
function Add-PortRule { | ||
<# | ||
.SYNOPSIS | ||
Adds a port rule for blocking/unblockin | ||
.DESCRIPTION | ||
Mainly meant to be an internal function to avoid repeated code | ||
.PARAMETER port | ||
The port or ports to control | ||
.PARAMETER protocol | ||
TCP,UDP, or BOTH | ||
.PARAMETER type | ||
Block or Unblock | ||
.LINK | ||
Add-PortRule | ||
.LINK | ||
Block-PortRule | ||
.LINK | ||
Unblock-PortRule | ||
.LINK | ||
New-NetfirewallRule | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(ValueFromPipeline=$true)] | ||
[string[]]$port, | ||
[Parameter()] | ||
[ValidateSet("TCP","UDP","BOTH")] | ||
[string]$protocol, | ||
[Parameter()] | ||
[ValidateSet("Block","Unblock")] | ||
[string]$type | ||
) | ||
|
||
begin { | ||
$newRules = New-Object System.Collections.Generic.List[object]; | ||
$i = 1; | ||
if ($type -eq "Unblock") { | ||
$action = "Allow"; | ||
} else { | ||
$action = "Block"; | ||
} | ||
switch ($protocol) { | ||
BOTH { | ||
$count = 4; | ||
} | ||
Default { | ||
$count = 2; | ||
} | ||
} | ||
} | ||
|
||
process { | ||
if ($protocol -eq "BOTH" -OR $protocol -eq "TCP") { | ||
$TCPRule = Get-PortRuleName -type $type -port $port -protocol "TCP"; | ||
if ($null -eq (Get-NetFirewallRule -Name "$TCPRule*") ) { | ||
Write-Progress -Activity "Creating Port Rules" -id 1 -Status "$i of $count" -CurrentOperation "Creating $TCPRule inBound Rule";$i++; | ||
$newRules.add((New-NetFirewallRule -DisplayName "$TCPRule inbound" -Name "$TCPRule inbound" -Action $action -Profile Any -Direction Inbound -Protocol TCP -LocalPort $port -EA 0)) | ||
|
||
Write-Progress -Activity "Creating Port Rules" -id 1 -Status "$i of $count" -CurrentOperation "Creating $TCPRule outbound Rule";$i++; | ||
$newRules.add((New-NetFirewallRule -DisplayName "$TCPRule outbound" -Name "$TCPRule outbound" -Action $action -Profile Any -Direction Outbound -Protocol TCP -LocalPort $port -EA 0)) | ||
} else { | ||
"$TCPRule already exists" | Out-Host; $i+=2; | ||
} | ||
} | ||
if ($protocol -eq "BOTH" -OR $protocol -eq "UDP") { | ||
$UDPRule = Get-PortRuleName -type $type -port $port -protocol "UDP"; | ||
if ($null -eq (Get-NetFirewallRule -Name "$UDPRule*") ) { | ||
Write-Progress -Activity "Creating Port Rules" -id 1 -Status "$i of $count" -CurrentOperation "Creating $UDPRule inbound Rule";$i++; | ||
$newRules.add((New-NetFirewallRule -DisplayName "$UDPRule inbound" -Name "$UDPRule inbound" -Action $action -Profile Any -Direction Inbound -Protocol UDP -LocalPort $port -EA 0)) | ||
|
||
Write-Progress -Activity "Creating Port Rules" -id 1 -Status "$i of $count" -CurrentOperation "Creating $UDPRule outbound Rule";$i++; | ||
$newRules.add((New-NetFirewallRule -DisplayName "$UDPRule outbound" -Name "$UDPRule outbound" -Action $action -Profile Any -Direction Outbound -Protocol UDP -LocalPort $port -EA 0)) | ||
} else { | ||
"$UDPRule already exists" | Out-Host; $i+=2; | ||
} | ||
} | ||
Write-Progress -Activity "Creating Port Rules" -id 1 -Status "$i of $count" -Completed | ||
|
||
} | ||
|
||
end { | ||
return $newRules; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
function Add-ProgramRule { | ||
<# | ||
.SYNOPSIS | ||
Adds program rules via pipe | ||
.DESCRIPTION | ||
Runs through the list of paths and makes the rules | ||
Mainly meant for internal use to avoid repeated code | ||
.PARAMETER paths | ||
The list of paths generated during Block/Unblock-Program | ||
.PARAMETER type | ||
Block or Unblock, used to determin rule name and rule action | ||
.EXAMPLE | ||
$paths | Add-ProgramRule | ||
.LINK | ||
Add-ProgramRule | ||
.LINK | ||
Block-Program | ||
.LINK | ||
Unblock-Program | ||
.LINK | ||
Remove-ProgramRule | ||
.LINK | ||
Get-ProgramRulename | ||
.LINK | ||
New-NetfirewallRule | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory=$true,ValueFromPipeline=$true)] | ||
$paths, | ||
[Parameter()] | ||
[ValidateSet("Block","Unblock")] | ||
[string]$type, | ||
$count | ||
) | ||
|
||
begin { | ||
$newRules = New-Object System.Collections.Generic.List[object]; | ||
$i = 1; | ||
# $count = $paths.count; | ||
} | ||
|
||
process { | ||
Write-Debug "paths list is $($paths | out-string)"; | ||
if ($type -eq "Unblock") { | ||
$action = "Allow"; | ||
} else { | ||
$action = "Block"; | ||
} | ||
$paths | Foreach-Object { | ||
$ProgramRule = Get-ProgramRuleName -type $type -program $name -exe "$($_.Name)"; | ||
Write-Progress -Activity "Creating Firewall Rules" -Status "$i of $count" -Id 1 -PercentComplete (($i/$count)*100) -CurrentOperation "Creating $ProgramRule rules"; | ||
|
||
if ($null -eq (Get-NetFirewallRule -Name "$ProgramRule*") ) { | ||
|
||
Write-Debug "Creating '$($programRule) inbound'"; | ||
Write-Progress -Activity "Creating $ProgramRule" -Status "creating inbound/outbound rules" -Id 2 -parentid 1 -CurrentOperation "Creating inbound rule"; | ||
$newRules.add((New-NetFirewallRule -DisplayName "$ProgramRule inbound" -Name "$ProgramRule inbound" -Action $action -Profile Any -Direction Inbound -Program "$($_.Fullname)")) | ||
|
||
Write-Debug "Creating '$($programRule) outbound'"; | ||
Write-Progress -Activity "Creating $ProgramRule" -Status "creating inbound/outbound rules" -Id 2 -parentid 1 -CurrentOperation "Creating outbound rule"; | ||
$newRules.add((New-NetFirewallRule -DisplayName "$ProgramRule outbound" -Name "$ProgramRule Outbound" -Action $action -Profile Any -Direction Outbound -Program "$($_.Fullname)")) | ||
|
||
Write-Progress -Activity "Creating $ProgramRule" -Status "creating inbound/outbound rules" -Id 2 -parentid 1 -Completed | ||
} else { | ||
"$ProgramRule already exists" | Out-Host; | ||
} | ||
$i++; | ||
} | ||
} | ||
|
||
end { | ||
Write-Progress -Activity "Creating Firewall Rules" -Status "$i of $count" -Id 1 -Completed; | ||
if ($null -eq $newRules) { | ||
"Some or all Rules already existed" | Out-Host | ||
} | ||
return $newRules; | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.