Functions/New-GSuiteUser.ps1
<#
.SYNOPSIS This function creates a GSuite user. #> function New-GSuiteUser { [CmdletBinding(PositionalBinding=$false)] [OutputType([PSCustomObject])] param ( # The first name for the user. [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$firstName, # The last name for the user. [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$lastName, # The primary email address for the user. [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$primaryEmailAddress, # The password for the user. [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$password ) # 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" Method = "POST" Headers = @{ "Content-Type" = "application/json" Accept = "application/json" Authorization = "Bearer $($Global:GSuiteAccessTokensHashTable.User)" } Body = @{ name = @{ familyName = $lastName givenName = $firstName } password = $password primaryEmail = $primaryEmailAddress } | ConvertTo-Json } # Invoke the REST call return Invoke-RestMethod @invokeRestMethodParams } |