I am trying to use Open-NetGPO on my domain controller in order to enable Windows Defender Firewall through the GPO:
New-GPO -Name test | New-GPLink -Target "dc=experiment,dc=local"
$GpoSession = Open-NetGPO -PolicyStore experiment.local\test
Set-NetFirewallProfile -All -GpoSession $GpoSessionName -Enabled True
Save-NetGPO -GPOSession $GpoSession
But I receive the error:
Open-NetGPO : The parameter is incorrect.
At line:2 char:15
+ $GpoSession = Open-NetGPO -PolicyStore experiment.local\test
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_NetGPO:root/standardcimv2/MSFT_NetGPO)
[Open-NetGPO], CimException
+ FullyQualifiedErrorId : Windows System Error 87,Open-NetGPO
When I run the script from the second line (because the first line can only work on a domain controller) on a different machine everything works fine.
What should be done differently in order for the whole script to run on the same machine?