We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Create Google Apps Account

February 03, 2023 Views: 3642

The script creates a Google Apps account for an Active Directory user.

Note: Before using the script, install and configure the GAM Tool on the computer where Adaxes service runs. For details, see GAM Wiki.


  • $gamPath - Specifies a path to the GAM executable file.
  • $waitTimeMilliseconds - Specifies the time to wait for GAM response. It is recommended not to set a time exceeding the 10 minutes' limit applied by Adaxes to scripts executed by business rules, custom commands and scheduled tasks. If a script runs for more time than you specify, it will be completed, but the errors, warnings and other messages will not be added to the Execution Log.
Edit Remove
$gamPath = "C:\Scripts\Gam\gam.exe" # TODO: modify me
$waitTimeMilliseconds = 8 * 60 * 1000 # TODO: modify me

# Get user information and build arguments
$argumentTemplate = "create user {0} firstname {1} lastname {2}"
$firstName = "%firstname%".Replace(" ", "")
$lastName = "%lastname%".Replace(" ", "")
if ([System.String]::IsNullOrEmpty("%unicodePwd%"))
    $Context.LogMessage("Google account created without password", "Warning")
    $argumentTemplate += " password '%unicodePwd%'"
$arguments = [System.String]::Format($argumentTemplate, @("%userPrincipalName%", $firstName, $lastName))

# Start GAM process
$processInfo = New-Object System.Diagnostics.ProcessStartInfo
$processInfo.FileName = $gamPath
$processInfo.RedirectStandardOutput = $true 
$processInfo.RedirectStandardError = $true
$processInfo.UseShellExecute = $false
$processInfo.CreateNoWindow = $true
$processInfo.Arguments = $arguments
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $processInfo
$process.Start() | Out-Null
$processCompleted = $process.WaitForExit($waitTimeMilliseconds)
if (!$processCompleted)
    Write-Error "The process timeout."
    return $null

$resultErrors = $process.StandardError.ReadToEnd()
$resultOutput = $process.StandardOutput.ReadToEnd()

# Create user account in Google
if (-not([System.String]::IsNullOrEmpty($resultErrors)))
    $Context.LogMessage($resultOutput, "Warning")
    $Context.LogMessage("An error occurred while creating a Google account. Error: " + $resultErrors, "Error")
elseif (!($resultOutput.StartsWith("Creating account")))
    $Context.LogMessage($resultOutput, "Information")
Comments 0
Leave a comment

Got questions?

Support Questions & Answers