Files
fn_registry/powershell/functions/infra/win_firewall_remove_rule.ps1
egutierrez 2fbf4ef62e feat: funciones PowerShell infra — firewall y portproxy
Funciones PowerShell para gestión de red en Windows: win_firewall_add_rule,
win_firewall_remove_rule, win_portproxy_add y win_portproxy_remove.
Útiles para configurar acceso de red en entornos WSL2.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 14:24:45 +02:00

34 lines
1.1 KiB
PowerShell

# win_firewall_remove_rule.ps1 - Removes a Windows Firewall rule by name.
# Requires: Administrator privileges
# Usage: powershell.exe -ExecutionPolicy Bypass -File win_firewall_remove_rule.ps1 -Name "CDP-9222"
param(
[Parameter(Mandatory = $true)]
[string]$Name
)
# Verify administrator privileges
$currentPrincipal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Error "ERROR: This script requires Administrator privileges. Run PowerShell as Administrator."
exit 1
}
# Check if the rule exists
$existingRule = netsh advfirewall firewall show rule name="$Name" 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "INFO: Firewall rule '$Name' does not exist - nothing to remove."
exit 0
}
# Remove the rule
Write-Host "Removing firewall rule '$Name'..."
netsh advfirewall firewall delete rule name="$Name"
if ($LASTEXITCODE -ne 0) {
Write-Error "ERROR: Failed to remove firewall rule '$Name'."
exit 1
}
Write-Host "OK: Firewall rule '$Name' removed."