Created
September 12, 2018 07:12
-
-
Save AshFlaw/59a8b173954cd075c64eab358deb6cbc to your computer and use it in GitHub Desktop.
Bulk add the OMS Log Analytics Network Monitoring rules to all machines in a domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function OMSICMPFWRules | |
{ | |
netsh advfirewall firewall add rule name="NPMDICMPV4Echo" protocol="icmpv4:8,any" dir=in action=allow | |
netsh advfirewall firewall add rule name="NPMDICMPV6Echo" protocol="icmpv6:128,any" dir=in action=allow | |
netsh advfirewall firewall add rule name="NPMDICMPV4DestinationUnreachable" protocol="icmpv4:3,any" dir=in action=allow | |
netsh advfirewall firewall add rule name="NPMDICMPV6DestinationUnreachable" protocol="icmpv6:1,any" dir=in action=allow | |
netsh advfirewall firewall add rule name="NPMDICMPV4TimeExceeded" protocol="icmpv4:11,any" dir=in action=allow | |
netsh advfirewall firewall add rule name="NPMDICMPV6TimeExceeded" protocol="icmpv6:3,any" dir=in action=allow | |
} | |
$Exclude = "server1.domain.local|server2.domain.local|server2.domain.local" # Server names to exlude. | |
$Computers = Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Where-Object {$_.DNSHostName -NotMatch $Exclude} | Select-Object -Expand DNSHostName # Get a list of servers from Active Directory. | |
foreach ($Computer in $Computers) | |
{ | |
try | |
{ | |
Write-Output "$(Get-Date) $Computer Adding Rules" | |
Invoke-Command -ComputerName $Computer -ScriptBlock ${function:OMSICMPFWRules} | |
} | |
catch | |
{ | |
Write-Output "$(Get-Date) $Computer Error Adding Rules" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment