SCRT-HQ / PSGSuite

Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
https://psgsuite.io/
Apache License 2.0
234 stars 68 forks source link

Update-GSUser support for unarchiving #379

Closed dominikduennebacke closed 6 months ago

dominikduennebacke commented 1 year ago

Update-GSUser allows archiving a user via the switch parameter Archived. However I did not find a way to unarchive a user in the same manner. Ideally the parameter should be changed from type [switch] to [bool] where $true represents archiving and $false unarchiving.

Current behavior for archiving

Update-GSUser -User "john.doe@test.com" -Archived

Desired behavior

# Archiving
Update-GSUser -User "john.doe@test.com" -Archived $true

# Unarchiving
Update-GSUser -User "john.doe@test.com" -Archived $false

This would match the Google Admin SDK API method users.update.

PUT https://admin.googleapis.com/admin/directory/v1/users/john.doe@test.com
{
  "archived": false
}
jeffreymcclain commented 8 months ago

I know this Issue was opened a while ago, but just to verify does

Update-GSUser -User "john.doe@test.com" -Archived:$true

and

Update-GSUser -User "john.doe@test.com" -Archived:$false

work as expected with the existing function and meet your desired use case?

According to the Microsoft documentation for PowerShell Switch parameter design considerations "Explicitly setting a switch from a boolean can be done with -MySwitch:$boolValue and in splatting with $params = @{ MySwitch = $boolValue }.

To your point, the Update-GSUser.ps1 function parameters could be changed from switches to booleans, but this might break existing uses of the function by other users. Someone could also create an alternate version of the function that has booleans instead of switches as a difference, but that also seems a bit excessive if the above workaround is functional.

dominikduennebacke commented 6 months ago

Hi @jeffreymcclain, sorry for my late reply as well.

Update-GSUser -User "john.doe@test.com" -Archived:$false does work as expected. Thanks for pointing it out. I was not aware you can explicitly set a swich parameter.

I have hence closed the ticket.