-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveFirewallRules.ps1
More file actions
30 lines (26 loc) · 1.06 KB
/
Copy pathRemoveFirewallRules.ps1
File metadata and controls
30 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 以管理员权限运行
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Error "错误: 脚本需要以管理员权限运行"
Start-Sleep -Seconds 5
exit 1
}
Write-Host "正在删除通过FirewallExeScanner生成的防火墙规则..."
Write-Host "=" * 60
# 获取所有防火墙规则
$rules = netsh advfirewall firewall show rule name=all | Select-String "Rule Name:"
# 遍历并删除符合条件的规则
$deletedCount = 0
foreach ($rule in $rules) {
$ruleName = $rule.ToString().Replace("Rule Name:", "").Trim()
if ($ruleName -like "Allow *.exe") {
Write-Host "删除规则: $ruleName"
netsh advfirewall firewall delete rule name="$ruleName"
$deletedCount++
}
}
Write-Host "=" * 60
Write-Host "规则删除完成!"
Write-Host "共删除 $deletedCount 个规则"
Write-Host ""
Write-Host "按任意键退出..."
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')