Script Repository


Create Google Apps Account

September 02, 2016
1424

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

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

Parameters:

  • $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
PowerShell
$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")
}
else
{
    $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.Arguments = $arguments
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $processInfo
$process.Start() | Out-Null
$process.WaitForExit($waitTimeMilliseconds)
$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 )
No results found.
Leave a comment