Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
SCOM monitor script for checking firewall status. Requires something like the PowerShell script monitor MP by Wei Lim: https://gallery.technet.microsoft.com/Sample-Management-Pack-17b76379
$API = New-Object -ComObject "MOM.ScriptAPI" -ErrorAction Stop
$PropertyBag = $API.CreatePropertyBag()
$Profiles = @{'Domain' = '0'; 'Standard' = '0'; 'Public' = '0'}
$Profiles.Domain = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile' -Name EnableFirewall).EnableFirewall
$Profiles.Standard = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile' -Name EnableFirewall).EnableFirewall
$Profiles.Public = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\PublicProfile' -Name EnableFirewall).EnableFirewall
if ($Profiles.Values -contains 0)
{
$PropertyBag.AddValue('State', 1)
$API.LogScriptEvent("FirewallState.ps1", 1009, 0, "One or more firewall profiles are disabled, see property bag for details.")
}
else
{
$PropertyBag.AddValue('State', 0)
$API.LogScriptEvent("FirewallState.ps1", 1000, 0, "All firewall profiles are enabled.")
}
foreach ($key in $Profiles.Keys)
{
$PropertyBag.AddValue($key, $($Profiles.Item($key)))
}
$PropertyBag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment