Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-GSUserLicense doesnt show all licenses #270

Closed
pompushko opened this issue Mar 19, 2020 · 14 comments
Closed

Get-GSUserLicense doesnt show all licenses #270

pompushko opened this issue Mar 19, 2020 · 14 comments
Assignees

Comments

@pompushko
Copy link

pompushko commented Mar 19, 2020

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):

  • OS: Windows 2016
  • PowerShell Version: 5.1.14393.3053
  • PSGSuite Version: 2.35.1
@pompushko pompushko changed the title Get-GSUserLicense didnt show all licenses Get-GSUserLicense doesnt show all licenses Mar 19, 2020
@scrthq
Copy link
Member

scrthq commented Mar 19, 2020

@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

@scrthq scrthq self-assigned this Mar 19, 2020
@pompushko
Copy link
Author

But i assign 2 licenses :D

image

@scrthq
Copy link
Member

scrthq commented Mar 19, 2020

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
Copy link
Author

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

I can post you this later

@scrthq
Copy link
Member

scrthq commented Mar 19, 2020

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
Copy link
Member

scrthq commented Mar 20, 2020

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 added a commit that referenced this issue Mar 20, 2020
## 2.36.3 - 2020-03-20

* [Issue #270](#270)
    * Added `CheckAll` switch parameter to `Get-GSUserLicense`
    * Updated `User` parameter aliases for all `*-GSUserLicense` functions to include `UserId` for better pipeline support.
* Miscellaneous
    * Updated GitHub Release section in psake.ps1 to POST the release to the Org URL due to failures.
scrthq added a commit that referenced this issue Mar 20, 2020
## 2.36.3 - 2020-03-20

* [Issue #270](#270)
    * Added `CheckAll` switch parameter to `Get-GSUserLicense`
    * Updated `User` parameter aliases for all `*-GSUserLicense` functions to include `UserId` for better pipeline support.
* Miscellaneous
    * Updated GitHub Release section in psake.ps1 to POST the release to the Org URL due to failures.
@scrthq
Copy link
Member

scrthq commented Mar 20, 2020

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
Copy link
Author

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
Copy link
Member

scrthq commented Mar 20, 2020

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 added a commit that referenced this issue Mar 20, 2020
## 2.36.4 - 2020-03-20

* [Issue #270](#270)
    * Corrected inaccurate warning that no licenses were found for a user when using the `CheckAll` switch on `Get-GSUserLicense`.
@scrthq
Copy link
Member

scrthq commented Mar 21, 2020

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

@pompushko
Copy link
Author

Yeah. All working fine now :D

@magic-happenz
Copy link

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
Copy link

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
Copy link

Buenno commented Aug 31, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants