exchange12rocks / PSGPPreferences

A way to manage Group Policy Preferences through PowerShell
MIT License
35 stars 2 forks source link

Set-GPPGroup -DeleteAllUsers or -DeleteAllGroups parameters produce error when policy contains multiple groups #27

Closed Borgquite closed 2 years ago

Borgquite commented 2 years ago

Consider this scenario:

New-GPPGroup -GPOName "TEST GPO" -Update -Name "Administrators"
Set-GPPGroup -GPOName "TEST GPO" -Name "Administrators" -DeleteAllUsers -DeleteAllGroups
New-GPPGroup -GPOName "TEST GPO" -Update -Name "Remote Desktop Users"
Set-GPPGroup -GPOName "TEST GPO" -Name "Remote Desktop Users" -DeleteAllUsers -DeleteAllGroups

The 'Administrators' group will be created correctly with Delete all users and Delete all groups set

The 'Remote Desktop Users' group will be created twice, and the second command will error out:

Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size."
At C:\Program Files\WindowsPowerShell\Modules\PSGPPreferences\0.2.0\Groups\Remove-GPPGroupsItem.ps1:117 char:21
+                     [void]$WorkObjects.Remove($ObjectToRemove)
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NotSupportedException

Seems that Set-GPPGroup can't handle multiple groups in a single policy

exchange12rocks commented 2 years ago

Thanks you Chris! Appreciate your bug reports!

exchange12rocks commented 2 years ago

Could you please check out the dev branch?

Borgquite commented 2 years ago

Hey, just tested, that seems to be working fine.

Thanks for the swift reply! This module shows a lot of promise, please do keep developing! I'll post a few more bugs in a minute.