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

Get-GSUserLicense issue #357

Open pompushko opened 2 years ago

pompushko commented 2 years ago

Hello

function SearchGSuiteUserLicenses($UserEmail)
{
    Write-Color @DisplayConsole "[i] ", "Working with: ", $UserEmail -Color White, White, Green
    $AccountGSuiteLicenses = $null
    # Check GSuite Licenses
    Try
    {
        $AccountGSuiteLicenses = Get-GSUserLicense -User $UserEmail -SkuId G-Suite-Enterprise -Verbose
    }
    Catch
    {
        $ErrorMessage = $_.Exception.Message
        Write-Color @DisplayConsole "[i] ", "Error: ", $ErrorMessage -Color White, White, Red
    }

    Try
    {
        $AccountGSuiteLicenses += Get-GSUserLicense -User $UserEmail -SkuId Google-Vault-Former-Employee -Verbose
    }
    Catch
    {
        $ErrorMessage = $_.Exception.Message
        Write-Color @DisplayConsole "[i] ", "Error: ", $ErrorMessage -Color White, White, Red
    }

    if ($AccountGSuiteLicenses -ne $null){
        Write-Color @DisplayConsole "[i] ", "License found: ", (($AccountGSuiteLicenses | Select-Object -Expand SkuName) -join ', ') -Color White, White, Green
        return (($AccountGSuiteLicenses | Select-Object -Expand SkuName) -join ', ')
    }
    else{
        return $null
    }
}
[2021-08-06 11:43:40] [i] Working with: user@DOMAIN.com
VERBOSE: Getting License SKU 'G-Suite-Enterprise' for User 'user@DOMAIN.com'
VERBOSE: Getting License SKU 'Google-Vault-Former-Employee' for User 'user@DOMAIN.com'
Get-GSUserLicense : Exception calling "Execute" with "0" argument(s): "Google.Apis.Requests.RequestError
User does not have a license for specified sku and product [404]
Errors [
    Message[User does not have a license for specified sku and product] Location[ - ] Reason[notFound] Domain[global]
]
"
At line:18 char:35
+ ... Licenses += Get-GSUserLicense -User $UserEmail -SkuId Google-Vault-Fo ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-GSUserLicense

[2021-08-06 11:43:40] [i] Error: Method invocation failed because [Google.Apis.Licensing.v1.Data.LicenseAssignment] does not contain a method named 'op_Addition'.
[2021-08-06 11:43:40] [i] License found: Google Workspace Enterprise Plus 
Buenno commented 10 months ago

I think you need to update your module as this function no longer exists. Update and try again.