PowerShell Windows Firewall

<# 

||||-- Disable all Windows Firewalls  --|||
netsh advfirewall set allprofiles state off

||||-- Enable all Windows Firewalls  --|||
netsh advfirewall set allprofiles state on

||||-- Show all Profiles --|||
netsh advfirewall show allprofiles

|||-- Get Windows Firewall Service Status --||
invoke-command localhost -Scriptblock {Get-Service | Where{$_Name -eq "MpsSvc"}

|||-- Set Windows Firewall Service Startup --||
Invoke-command ServerName -Scriptblock {

    Get-Service | Where{$_.Name -eq "MpsSvc"} | Set-Service -StartupType Automatic

    Sleep 2

    Get-Service | Where{$_.Name -eq "MpsSvc"} | Start-Service

}

||||--No WinRM Access - Use PSEXEC to Disable --|||
cmd /s /c "psexec.exe \\ServerName netsh firewall set opmode disable 2>&1"

#>

‚Äč

#|||||--List of Systems to Check Windows Firewall Setup--||||
$SystemstoCheck=Get-Content C:\Temp\CheckMyFirewall.txt

#||||--Invoke Command - WinRM Capable--|||||
Try{
    invoke-command -ErrorAction SilentlyContinue $SystemstoCheck -scriptblock {    
    $Env:Computername 
    netsh advfirewall show Domainprofile 
    }}Catch{
    $_.Exception 
}

2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator