"Find is your friend"!!

Try this:
 Code:
; Rule exists
$Cmd = '%COMSPEC% /c netsh advfirewall firewall show rule name="SNMP Trap Service (UDP In)" | find /i "No rules match" >NUL: 2>&1'
Shell $Cmd
$IsPresent = @ERROR
'Rule is present - Result: ' $IsPresent ?

; Rule does not exist (search for "UDP Out" instead of "UDP In")
$Cmd = '%COMSPEC% /c netsh advfirewall firewall show rule name="SNMP Trap Service (UDP Out)" | find /i "No rules match" >NUL: 2>&1'
Shell $Cmd
$IsPresent = @ERROR
'Rule is not present - Result: ' $IsPresent ?
When a rule is not present, a string containing "No rules match..." is displayed. Using FIND.EXE to search for this text will return a 0 when found and a 1 when not.. which translates to 1=Present, 0=Not Present. From there, the logic should be pretty easy. \:\) If Not $IsPresent {add-rule} EndIf.

To clarify - FIND will return SUCCESS (0) when it finds the search text, and FAIL (1) when it doesn't. This creates a simple Boolean result that is returned to Kix in the @ERROR macro.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D