I'm trying to process firewall rules in a powershell script - here is the line I'm using:
$currentRules = get-netfirewallRule -CimSession computer4 -direction Inbound
So this works fine if it returns any rules, returns a collection of some sort which are stored in $currentRules. All good.
the problem arises if get-netfirewallrule doesn't find any matches - I get a helpful
get-netfirewallRule : computer4: No MSFT_NetFirewallRule objects found with property 'Direction' equal to 'Inbound'. Verify the value of the property and retry.
At line:1 char:1
+ get-netfirewallRule -CimSession computer4 -direction Inbound | ou ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Inbound:Direction) [Get-NetFirewallRule], CimJobException
+ FullyQualifiedErrorId : CmdletizationQuery_NotFound_Direction,Get-NetFirewallRule
+ PSComputerName : computer4
splatted in the middle of my output. I've tried the usual > $null and | out-null, but still the output ends up on my screen. Any ideas how I can stop it displaying this 'useful' message?
thanks,
Jim