Script repository
The scripts reset the user password in Google Apps. To execute the scripts, create a business rule, scheduled task or custom command configured for the User object type.
Script 1: Using Google API
To use the script:
- Download Google Data API and install it on the computer where Adaxes service runs.
- Enable Google Provisioning API in your Google application.
Parameters
$userName- the username of the target user in Google Apps. You can use value references (e.g. %username%) in the template.$userPassword- the password to set in Google Apps. You can use value references (e.g. %fullname%) in the template.$domainName- the name of the domain registered in your Google application.$adminEmail- the username of a user with administrative privileges in your Google Application. The account will be used to make the request to Google Apps.$adminPassword- the password of a user with administrative privileges in your Google Application. The account will be used to make the request to Google Apps.
# Load Google Data API DLL.
[Reflection.Assembly]::LoadFrom("C:\Program Files\Google\Google Data API SDK\Redist\Google.GData.Apps.dll") # TODO: modify me
$userName = "%sAMAccountName%" # TODO: modify me
$userPassword = "%firstname%%lastname%" # TODO: modify me
$domainName = "domain.com" # TODO: modify me
$adminEmail = "administrator@domain.com" # TODO: modify me
$adminPassword = "password" # TODO: modify me
# Connect to Google Apps.
$service = New-Object "Google.GData.Apps.AppsService" ($domainName, $adminEmail, $adminPassword)
# Get user in Google Apps.
try
{
$userEntry = $service.RetrieveUser($userName)
}
catch
{
$Context.LogMessage("User not found in Google Apps", "Error") # TODO: modify me
return
}
# Update the password in Google Apps.
$login = $userEntry.Login
$login.Password = $userPassword
$userEntry.Login = $login
try
{
$service.UpdateUser($userEntry)
}
catch
{
$baseException = $_.Exception.GetBaseException()
if ($baseException -ne $NULL -and $baseException.Response -ne $NULL)
{
if ($baseException.Response.StatusCode -eq "BadRequest")
{
$Context.LogMessage("The password does not meet the password policy", "Error") # TODO: modify me
return
}
}
$Context.LogMessage($_.Exception.GetBaseException().Message, "Error")
}Script 2: using gShell
In the script, the $userID variable specifies a value reference for the identifier of the user for which to reset the password. You can use email address (%mail%) or username (%sAMAccountName%).
Before using the script, perform the steps listed in gShell’s Getting Started document. All the steps must be performed using the credentials of the Adaxes service account (specified during Adaxes installation).
$scriptBlock = {
Import-Module gShell
$userID = "%mail%" # TODO: modify me
$newPassword = "Password" # TODO: modify me
Set-GAUser -UserKey $userID -NewPassword $newPassword
}
try
{
Invoke-Command -ComputerName localhost -ScriptBlock $scriptBlock -ErrorAction Stop
}
catch
{
$Context.LogMessage("An error occurred when reseting password for user. Error: " + $_.Exception.Message, "Warning")
}
Comments 0
You must be signed in to comment.