All Tweaks

Firewall & Security

Disable File and Printer Sharing

Disable firewall rules for file and printer sharing if not needed

Benefit

Prevents unauthorized access to shared files and printers on network

Impact

medium

Commands (1)

$ErrorActionPreference='Continue'; $groupList = @(@{Primary='File and Printer Sharing'; Aliases=@('File and Printer Sharing','File and Printer Sharing','Compartir archivos e impresoras','@FirewallAPI.dll,-28502')}); foreach ($g in $groupList) { $found = $null; foreach ($alias in $g.Aliases) { $rules = Get-NetFirewallRule -Group $alias -ErrorAction SilentlyContinue; if (-not $rules) { $rules = Get-NetFirewallRule -ErrorAction SilentlyContinue | Where-Object { $_.DisplayGroup -eq $alias } } if ($rules) { $found = $rules; break } } if (-not $found) { Write-Host "[SKIP] $($g.Primary) - no matching rules on this system"; continue } $enabled = @($found | Where-Object { $_.Enabled -eq 'True' -or $_.Enabled -eq $true }); if ($enabled.Count -eq 0) { Write-Host "[OK] $($g.Primary) - already disabled ($($found.Count) rule(s))"; continue } try { $enabled | Disable-NetFirewallRule -ErrorAction Stop; Write-Host "[OK] $($g.Primary) - disabled $($enabled.Count) rule(s)" } catch { Write-Host "[ERR] $($g.Primary) - $($_.Exception.Message)" } }