The PowerShell script provided here resets a user's password in G Suite. ADSelfService Plus, an Active Directory (AD) self-service password management, and single sign-on solution, offers the Password Reset feature that allows users to reset their AD passwords. It also offers the Password Synchronization feature that syncs users’ passwords and any changes to it with their user accounts in applications like G Suite. When both these features are configured, users can use the same password to log into G Suite and their AD domain, and can reset this password without help desk intervention. Here is a comparison between resetting user's G Suite passwords using PowerShell and ADSelfService Plus.
G Suite passwords can be reset using a set of PowerShell cmdlets called gShell. Run the following script to reset a user's G Suite password:
$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")
}ADSelfService Plus's Password Reset feature allows users to reset their G Suite passwords without any help-desk intervention. This reduces the workload of help desk administrators and improves the user's productivity.
Feature configuration is as simple as:
The Password Synchronization feature synchronizes the changes made to a user's AD password with other integrated applications like G Suite, Office 365, Salesforce, and much more.
Configuration involves:
When both these configurations are set to be true, users can reset their G Suite passwords, and it will be synced with their AD domain accounts automatically.
Screenshots:
Ensure you have the required module by running the script below.
Install-Module GoogleWorkspace -Scope CurrentUserConnect using API credentials. This allows PowerShell to communicate with Google Workspace.
Connect-GoogleWorkspace -ClientID "your-client-id" -ClientSecret "your-secret-key"Set a new password for a specific user. The script below updates the password for user@example.com.
Set-GoogleWorkspaceUserPassword -User "user@example.com" -NewPassword "NewSecurePassword!"Send an email notification about the password change to ensure users are informed about the change.
Send-MailMessage -To "user@example.com" -From "admin@yourdomain.com" -Subject "Password Reset" -Body "Your password has been reset. Please change it upon login."Use Google’s API with PowerShell to reset a Google Workspace user’s password.
Set-GoogleUserPassword -User user@domain.com -NewPassword "NewPass@123"Yes, you can force users to change passwords at the next login by modifying user settings in Google Admin Console.
Yes, you can bulk reset passwords for multiple users with Google API scripting.