-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6efa5e7
commit a5ac3a5
Showing
5 changed files
with
149 additions
and
0 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
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,142 @@ | ||
|
||
<# | ||
MIT License | ||
This file is part of "Windows Firewall Ruleset" project | ||
Homepage: https://github.com/metablaster/WindowsFirewallRuleset | ||
Copyright (C) 2023 metablaster zebal@protonmail.ch | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
#> | ||
|
||
<# | ||
.SYNOPSIS | ||
Outbound rule for Microsoft PowerToys | ||
.DESCRIPTION | ||
Outbound rule for Microsoft PowerToys | ||
.PARAMETER Domain | ||
Computer name onto which to deploy rules | ||
.PARAMETER Trusted | ||
If specified, rules will be loaded for executables with missing or invalid digital signature. | ||
By default an error is generated and rule isn't loaded. | ||
.PARAMETER Interactive | ||
If program installation directory is not found, script will ask user to | ||
specify program installation location. | ||
.PARAMETER Quiet | ||
If specified, it suppresses warning, error or informationall messages if user specified or default | ||
program path does not exist or if it's of an invalid syntax needed for firewall. | ||
.PARAMETER Force | ||
If specified, no prompt to run script is shown | ||
.EXAMPLE | ||
PS> .\PowerToys.ps1 | ||
.INPUTS | ||
None. You cannot pipe objects to PowerToys.ps1 | ||
.OUTPUTS | ||
None. PowerToys.ps1 does not generate any output | ||
.NOTES | ||
None. | ||
#> | ||
|
||
#Requires -Version 5.1 | ||
#Requires -RunAsAdministrator | ||
|
||
[CmdletBinding()] | ||
param ( | ||
[Alias("ComputerName", "CN")] | ||
[string] $Domain = [System.Environment]::MachineName, | ||
|
||
[Parameter()] | ||
[switch] $Trusted, | ||
|
||
[Parameter()] | ||
[switch] $Interactive, | ||
|
||
[Parameter()] | ||
[switch] $Quiet, | ||
|
||
[Parameter()] | ||
[switch] $Force | ||
) | ||
|
||
#region Initialization | ||
. $PSScriptRoot\..\..\..\..\..\Config\ProjectSettings.ps1 $PSCmdlet -Domain $Domain | ||
Initialize-Project | ||
. $PSScriptRoot\..\..\DirectionSetup.ps1 | ||
|
||
Import-Module -Name Ruleset.UserInfo | ||
|
||
# Setup local variables | ||
$Group = "Microsoft - PowerToys" | ||
$Accept = "Outbound rule for Microsoft PowerToys will be loaded" | ||
$Deny = "Skip operation, outbound rule for Microsoft PowerToys will not be loaded" | ||
if (!(Approve-Execute -Accept $Accept -Deny $Deny -ContextLeaf $Group -Force:$Force)) { exit } | ||
|
||
$PSDefaultParameterValues["Confirm-Installation:Quiet"] = $Quiet | ||
$PSDefaultParameterValues["Confirm-Installation:Interactive"] = $Interactive | ||
$PSDefaultParameterValues["Test-ExecutableFile:Quiet"] = $Quiet | ||
$PSDefaultParameterValues["Test-ExecutableFile:Force"] = $Trusted -or $SkipSignatureCheck | ||
#endregion | ||
|
||
# First remove all existing rules matching group | ||
Remove-NetFirewallRule -PolicyStore $PolicyStore -Group $Group -Direction $Direction -ErrorAction Ignore | ||
|
||
# PowerToys App installation directories | ||
$PowerToysRoot = "%ProgramFiles%\PowerToys" | ||
|
||
# | ||
# Rules for Microsoft PowerToys | ||
# | ||
|
||
# Test if installation exists on system | ||
if ((Confirm-Installation "PowerToys" ([ref] $PowerToysRoot)) -or $ForceLoad) | ||
{ | ||
$Program = "$PowerToysRoot\PowerToys.exe" | ||
if ((Test-ExecutableFile $Program) -or $ForceLoad) | ||
{ | ||
New-NetFirewallRule -DisplayName "PowerToys" ` | ||
-Platform $Platform -PolicyStore $PolicyStore -Profile $DefaultProfile ` | ||
-Service Any -Program $Program -Group $Group ` | ||
-Enabled True -Action Allow -Direction $Direction -Protocol TCP ` | ||
-LocalAddress Any -RemoteAddress Internet4 ` | ||
-LocalPort Any -RemotePort 80, 443 ` | ||
-LocalUser $UsersGroupSDDL ` | ||
-InterfaceType $DefaultInterface ` | ||
-Description "PowerToys needs internet to check for updates" | | ||
Format-RuleOutput | ||
} | ||
} | ||
|
||
if ($UpdateGPO) | ||
{ | ||
Invoke-Process gpupdate.exe | ||
Disconnect-Computer -Domain $Domain | ||
} | ||
|
||
Update-Log |
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