Functions/Remove-GSuiteOrganizationalUnit.ps1
<#
.SYNOPSIS This function removes one GSuite organizational unit. #> function Remove-GSuiteOrganizationalUnit { [CmdletBinding(PositionalBinding=$false)] [OutputType([Bool])] param ( # The full path for the organizational unit. [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$path ) # Validate that the 'connection' has been established and the organizational unit access token exists Assert-GSuiteConnection -Scope "OrganizationalUnit" # Remove the '/' at the beginning of the path $path = $path.TrimStart("/") # Prepare REST call parameters $invokeRestMethodParams = @{ Uri = "https://www.googleapis.com/admin/directory/v1/customer/my_customer/orgunits/$($path)" Method = "DELETE" Headers = @{ Accept = "application/json" Authorization = "Bearer $($Global:GSuiteAccessTokensHashTable.OrganizationalUnit)" } } # 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 } } |