PowerShell set firewall rule across domain

Asphyxia

Owner
Administrator
Apr 25, 2015
1,845
2
2,199
327
Create a file named Masshole.ps1
Code:
$Cred = Get-Credential

foreach($line in Get-Content .\hosts.txt) {

Invoke-Command -ComputerName $line -ScriptBlock { New-NetFirewallRule -DisplayName 'Block Inbound Port 135' -Direction Inbound -LocalPort 135 -Protocol TCP -Action Block } -credential $Cred

}

pause


Then create a ".txt" file named "hosts.txt" in the same directory and place all your hostnames e.g.
Code:
winhost1.ciphers.pw
winhost2.ciphers.pw
winhost3.ciphers.pw
winhost4.ciphers.pw
winserv-test.ciphers.pw
winserv-dev.ciphers.pw
winserv-auth.ciphers.pw

That should do just fine, alter everything in the ScriptBlock { (braces) as needed. Have fun, be safe!!
 
Top