I want to change all Firewall rules to only apply to Public profile, so I tried this:
$rules = Get-NetFirewallRule | select Name
$rules | ForEach-Object {Set-NetFirewallRule -Name $rules -Profile Public}
but i keep getting Quota violation errors like this:
Set-NetFirewallRule : Quota violation
At line:3 char:26
+ ... s | ForEach-Object {Set-NetFirewallRule -Name $rules -Profile Public}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_NetFirewallRule:root/standardcimv2/MSFT_NetFirewallRule) [Set-NetFirewallRule], CimExcepti
on
+ FullyQualifiedErrorId : HRESULT 0x8004106c,Set-NetFirewallRule
Set-NetFirewallRule : Quota violation
At line:3 char:26
+ ... s | ForEach-Object {Set-NetFirewallRule -Name $rules -Profile Public}
how can I fix this? tried it in PowerShell 5.1 and PowerShell 7.x too.
The issue is, that you currently query all rules and store them in the variable called $rules
. Then you loop through those rules but once you set the new rule you do not assign the single element of the variable $rules
to the parameter Name
, you assign them all. So a working version would be:
Get-NetFirewallRule | ForEach-Object {Set-NetFirewallRule -Name $_.name -Profile Public}
As you said the processing is slow you want to process the items in parallel you may have a look at:
.net runspaces: https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.runspaces.runspace?view=powershellsdk-7.0.0
or the built-in feature of PS7: https://devblogs.microsoft.com/powershell/powershell-foreach-object-parallel-feature/