Functions/Remove-GSuiteUser.ps1
<#
.SYNOPSIS This function removes one GSuite user. #> function Remove-GSuiteUser { [CmdletBinding(PositionalBinding=$false)] [OutputType([Bool])] param ( # The access token. # It has to be generated using a refresh token, from Get-GSuiteAccessToken [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$token, # The primary email address for the user. [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$primaryEmailAddress ) # Prepare REST call parameters $invokeRestMethodParams = @{ Uri = "https://www.googleapis.com/admin/directory/v1/users/$($primaryEmailAddress)" Method = "DELETE" Headers = @{ Accept = "application/json" Authorization = "Bearer $($token)" } } # Invoke the REST call $response = Invoke-RestMethod @invokeRestMethodParams # If the removal is successful, $response will be an empty string if ("" -eq $response) { return $true } else { return $false } } |