exchange12rocks / PSGPPreferences

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

Set-GPPUser destroys group definition in the XML #21

Closed exchange12rocks closed 2 years ago

exchange12rocks commented 2 years ago
New-GPPGroup -Name 'grp1' -Update -GPOName TEST -NewName 'nname'
New-GPPUser -Name 'sd' -Update -GPOName TEST -UserMayNotChangePassword
Set-GPPUser -Name sd -GPOName test -Action Delete -NewName 'aaa' -FullName 'fulln' -Description 'aweso' -AccountDisabled $true -UserMayNotChangePassword $true -Disable $true
Remove-GPPGroupsItem : Parameter set cannot be resolved using the specified named parameters.
At C:\PSGPPreferences\Groups\Remove-GPPUser.ps1:46 char:5
+     Remove-GPPGroupsItem @PSBoundParameters -Context $Context -ItemTy ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Remove-GPPGroupsItem], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Remove-GPPGroupsItem
<?xml version="1.0" encoding="utf-8"?><Groups clsid="{3125e937-eb16-4b4c-9934-544fc6d24d26}" disabled="0"><User clsid="{df5f1855-51e5-4d24-8b1a-d9bde98ba1d1}" bypassErrors="1" changed="2022-01-15 19:28:46" disabled="1" image="3" name="sd" removePolicy="0" uid="{d95abbb1-2771-4d3a-b04a-d835834d1c7d}"><Properties acctDisabled="0" action="D" changeLogon="0" description="" expires="" fullName="" neverExpires="0" newName="" noChange="0" userName="" /></User></Groups>
  1. Why does the group definition get removed when we do not touch it?
  2. What parameters get passed to Remove-GPPGroupsItem which it cannot resolve?

Repeated run:

PS C:\PSGPPreferences> Set-GPPUser -Name sd -GPOName test -Action Delete -NewName 'aaa' -FullName 'fulln' -Description 'aweso' -AccountDisabled $true -UserMayNotChangePassword $true -Disable $true
The property 'Action' cannot be found on this object. Verify that the property exists and can be set.
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:159 char:54
+             $InputObject.Properties.Action = switch ($Action) {
+                                                      ~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'changeLogon' cannot be found on this object. Verify that the property exists and can be set.
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:179 char:21
+                     $InputObject.Properties.changeLogon = $null
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'noChange' cannot be found on this object. Verify that the property exists and can be set.
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:185 char:21
+ ...             $InputObject.Properties.noChange = $UserMayNotChangePassw ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'newName' cannot be found on this object. Verify that the property exists and can be set.
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:190 char:17
+                 $InputObject.Properties.newName = $NewName
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'fullName' cannot be found on this object. Verify that the property exists and can be set.
At C:\Groups\Set-GPPUser.ps1:193 char:17
+                 $InputObject.Properties.fullName = $FullName
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'description' cannot be found on this object. Verify that the property exists and can be set.
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:196 char:17
+                 $InputObject.Properties.description = $Description
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'acctDisabled' cannot be found on this object. Verify that the property exists and can be set.
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:199 char:17
+ ...               $InputObject.Properties.acctDisabled = $AccountDisabled
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'disabled' cannot be found on this object. Verify that the property exists and can be set.
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:219 char:13
+             $InputObject.disabled = $Disable
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'image' cannot be found on this object. Verify that the property exists and can be set.
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:222 char:9
+         $InputObject.image = $InputObject.Properties.action.value__ # ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Remove-GPPUser : Cannot process argument transformation on parameter 'UID'. Cannot convert null to type "System.Guid".
At C:\PSGPPreferences\Groups\Set-GPPUser.ps1:224 char:70
+ ... ection = Remove-GPPUser -GPPSection $GPPSection -UID $InputObject.uid
+                                                          ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Remove-GPPUser], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-GPPUser

gets us this:

<?xml version="1.0" encoding="utf-8"?><Groups clsid="{3125e937-eb16-4b4c-9934-544fc6d24d26}" disabled="0" />

The user definition WAS there - why did it get deleted too?

exchange12rocks commented 2 years ago

Closed by 3cf61f277b302654c91e39b6d754a392c0b600f2