Skip to content

Instantly share code, notes, and snippets.

@AshFlaw
Created September 12, 2018 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshFlaw/59a8b173954cd075c64eab358deb6cbc to your computer and use it in GitHub Desktop.
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
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