Functions/Set-GSuiteAdministrator.ps1
<# .SYNOPSIS This function assigns or unassigns a GSuite user as an administrator. #> function Set-GSuiteAdministrator { [CmdletBinding(PositionalBinding=$false)] [OutputType([Bool])] param ( # The primary email address of the user. [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$primaryEmailAddress, # Whether the user will be an administrator or not. [Parameter(Mandatory=$true)] [ValidateNotNull()] [Switch]$isAdmin ) # Validate that the 'connection' has been established and the user access token exists Assert-GSuiteConnection -Scope "User" # Prepare REST call parameters $invokeRestMethodParams = @{ Uri = "https://www.googleapis.com/admin/directory/v1/users/$($primaryEmailAddress)/makeAdmin" Method = "POST" Headers = @{ "Content-Type" = "application/json" Accept = "application/json" Authorization = "Bearer $($Global:GSuiteAccessTokensHashTable.User)" } Body = @{ status = $isAdmin.IsPresent } | ConvertTo-Json } # Invoke the REST call $response = Invoke-RestMethod @invokeRestMethodParams # If the update is successful, $response will be an empty string return ("" -eq $response) } |