Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.