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 66 forks source link

Get-GSUserLicense doesnt show all licenses #270

Closed pompushko closed 4 years ago

pompushko commented 4 years ago

Describe the bug Get-GSUserLicense doesnt show all licenses

To Reproduce Steps to reproduce the behavior:

  1. Get-GSUserLicense -User USER
  2. Show only one license
  3. Get-GSUserLicense -User USER -License Google-Vault
  4. Show Google Vault license
  5. Get-GSUserLicense -User USER -License Google-Apps-For-Business
  6. Show G Suite Basic license
  7. Get-GSUserLicense -User USER | ForEach-Object { Remove-GSUserLicense -User $_.UserId -License $_.SkuId -Confirm }
  8. Remove only one (or first) license which you can see in 1 item.

Environment (please complete the following information):

scrthq commented 4 years ago

@pompushko - For the target user, what licenses do they have assigned to them in the Admin console? In your description, you mention Google-Vault and Google-Apps licenses, but you can't have both a Vault license and a Google-Apps license on the same user. I'm not aware of any situations where multiple licenses can be attached to a single user so I might be missing something, but your example makes sense in that those 2 license types would definitely conflict with each other.

Get-GSUserLicense is designed to return the first license it sees when you specify a user based on the assumption that only one license can be assigned to a user at any given time so that it doesn't waste cycles on checking every license type available, but it would be easy enough to add a switch that allows you to force searching across all license types available.

You can alternatively do something like this to find all licenses attached to a specific user:

Get-GSUserLicense -Verbose | Where-Object {$_.UserId -eq $user}

If you wanted to handle removing just the first license found only, you could just do the below with the current behavior since Get-GSUserLicense currently short circuits on the first match.

Note that the property on the returned on the license object has the user's email as the UserId property, so the User parameter will still need to be specified on Remove-GSUserLicense until that's corrected

# Current
Get-GSUserLicense -User $user | Remove-GSUserLicense -User $user
# Future
Get-GSUserLicense -User $user | Remove-GSUserLicense
pompushko commented 4 years ago

But i assign 2 licenses :D

image

scrthq commented 4 years ago

Weird, this is the first time I've seen both Vault and Basic licenses assigned, but I guess that's because it's normal Vault, not Vault-Former-Employee. Noted! Taking this as a feature request.

pompushko commented 4 years ago

Yeah, but when you assign Vault-Former-Employee - script throw error with something like "same product assigned"

I can post you this later

scrthq commented 4 years ago

Yes, Google-Vault is the product sku for both Google-Vault and Google-Vault-Former-Employee license ID's. You would need to remove the Google-Vault license then add the Google-Vault-Former-Employee license. You can't have multiple licenses from the same product ID assigned to a user.

scrthq commented 4 years ago

Working on adding that switch parameter to Get-GSUserLicense right now. As an additional FYI, if you want to switch licenses within the same product SKU, you'll want to use Update-GSUserLicense instead of Set-GSUserLicense.

scrthq commented 4 years ago

hey @pompushko - I've just released an update to accommodate the request to get all licenses for a user in version 2.36.3. Update when you can!

To get all licenses for a user, just pass the CheckAll switch to Get-GSUserLicense, e.g.:

Get-GSUserLicense -User $user -CheckAll

Also, you should now be able to simply pipe the output of Get-GSUserLicense into Remove-GSUserLicense without specifying the User parameter on both functions:

# Remove the first license matched only
Get-GSUserLicense -User $user | Remove-GSUserLicense

# Remove all licenses
Get-GSUserLicense -User $user -CheckAll | Remove-GSUserLicense

# Remove just a specific license type
Get-GSUserLicense -User $user -License Google-Vault | Remove-GSUserLicense
pompushko commented 4 years ago

Tested. PSGsuite updated up to 2.35.3, it show 2 licenses(assigned to user) and after that show line "WARNING: No license found for USER!"

scrthq commented 4 years ago

Ahhhhh, I know why that is. I'll get a new version out today, I'm glad you're getting both licenses back now though 🙂

scrthq commented 4 years ago

Alright, version 2.36.4 is out and you should be good to go now @pompushko

pompushko commented 4 years ago

Yeah. All working fine now :D

magic-happenz commented 2 years ago

Thhis seems still not fixed. I am on version 2.36.4 which seems to be the last one and when I run Get-GSUserLicense -User "username" I don´t get any licenses back. Even though when I run the commandlet whithout options I can see that this user got licenses in the list of all users...

robertbatchelor commented 2 years ago

Thhis seems still not fixed. I am on version 2.36.4 which seems to be the last one and when I run Get-GSUserLicense -User "username" I don´t get any licenses back. Even though when I run the commandlet whithout options I can see that this user got licenses in the list of all users...

@magic-happenz

I believe this is because this module hasn't been updated in some time, and doesn't account for the new license changes in Google Workspace.

I'm not sure exactly how this works, but I presume all of the license types at the time of the last update are hard coded into this module. If you try something like this Get-GSUserLicense -License "Google-Workspace-Enterprise-Standard" with the module now, it will return an error with what I presume all of the License names it was expecting to see, none of these include workspace.

Get-GSUserLicense: Cannot validate argument on parameter 'License'. The argument "Google-Workspace-Enterprise-Standard" does not belong to the set "16tb,1tb,200gb,20gb,2tb,400gb,4tb,50gb,8tb,basic,businessarchived,cdm,chrome,Cloud-Identity,Cloud-Identity-Premium,cloudidentity,cloudidentitypremium,coordinate,d4e,Drive-Enterprise,drive16tb,drive1tb,drive200gb,drive20gb,drive2tb,drive400gb,drive4enterprise,drive4tb,drive50gb,drive8tb,driveenterprise,e4e,e4es,enterprise,enterprisearchived,free,G-Suite-Basic,G-Suite-Business,G-Suite-Business-Archived,G-Suite-Enterprise,G-Suite-Enterprise-Archived,G-Suite-Enterprise-for-Education,G-Suite-Enterprise-for-Education-Student,G-Suite-Free-Standard,G-Suite-Government,G-Suite-Lite,G-Suite-Message-Security,gae,gafb,gafg,gafw,gal,gams,gau,Google-Chrome-Device-Management,Google-Coordinate,Google-Drive-Storage-16TB,Google-Drive-Storage-1TB,Google-Drive-Storage-200GB,Google-Drive-Storage-20GB,Google-Drive-Storage-2TB,Google-Drive-Storage-400GB,Google-Drive-Storage-4TB,Google-Drive-Storage-50GB,Google-Drive-Storage-8TB,Google-Vault,Google-Vault-Former-Employee,Google-Voice-Premier,Google-Voice-Standard,Google-Voice-Starter,googlechromedevicemanagement,googlecoordinate,googledrivestorage16tb,googledrivestorage1tb,googledrivestorage200gb,googledrivestorage20gb,googledrivestorage2tb,googledrivestorage400gb,googledrivestorage4tb,googledrivestorage50gb,googledrivestorage8tb,googlevault,googlevaultformeremployee,googlevoicepremier,googlevoicestandard,googlevoicestarter,gsb,gsbau,gse,gseau,gsefe,gsefes,gsl,gsuitebasic,gsuitebusiness,gsuitebusinessarchived,gsuiteenterprise,gsuiteenterprisearchived,gsuiteenterpriseeducation,gsuiteenterpriseeducationstudent,gsuitegams,gsuitegov,gsuitegovernment,gsuitelite,gsuitemessagesecurity,gsuitepostini,gvpremier,gvstandard,gvstarter,identity,identitypremium,lite,postini,standard,unlimited,vault,vfe,voicepremier,voicestandard,voicestarter" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.

It's a shame but this module is unfortunately getting less and less useful the more out of date it becomes :(

Buenno commented 12 months ago

I'm working on updating the licences to match the Google Dev documentation but noticed that even if you run Get-GSUserLicense user.name then nothing is returned.

This appears to be caused by this section of code: if (-not $CheckAll -and $response) { $matchedLicense = $true break }

If the checkall param wasn't set, and an API response was received, then set the matchedLicence variable to true, then break. Nothing here is returning the results to the terminal.

My licence change will also fix this issue by returning the results to terminal.