Tutorial on how to Manage Google G Suite with PowerShell
Readiness on Google G Suite & Developer Console
Creating the Project & Service Account
Login to Google Developers Console with G Suite Admin to create a new project
Enter Project Name called PSGSuite and click CREATE
Verify Project called PSGSuite is selected, and go to APIs & Services – Credentials – Create Credentials
Select Service Account
Enter Service Account Name called PSGSuite and click CREATE
Select Owner to have full access to all resources and click CREATE
Click Done
Creating P12 File
Create Key for the newly created service account
Select P12 format
The p12 file will be downloaded to your computer automatically and keep the Private Key password securely
Enable Domain Wide Delegation
Click on the newly created service account and click Edit
Enable G Suite Domain Wide Delegation and enter product name called PSGSuite
Enable API Access
Go To APIs & Services and click on ENABLE APIS AND SERVICES
Enter Admin SDK in the search bar
Click ENABLE to allow API Access
Repeat the same steps to enable API Access for the following
- Admin SDK
- Apps Activity API
- Contacts API
- Drive Activity API
- Enterprise License Manager API
- Gmail API
- Google Calendar API
- Google Classroom API
- Google Docs API
- Google Drive API
- Google Sheets API
- Google Slides API
- Groups Settings API
- Hangouts Chat API
- People API
- Tasks API
OAuth Client ID & App Email
Save the Client ID & App Email in Notepad as it is required in the configuration later
API Client Access in G Suite Admin Console
Login to Google Admin Console with Admin Credential and click on Security – Advanced Settings – Manage Domain-wide delegation
Enter the Client ID & OAuth Scopes below and click AUTHORISE
https://apps-apis.google.com/a/feeds/emailsettings/2.0/,
https://mail.google.com/,
https://sites.google.com/feeds,
https://www.google.com/m8/feeds/contacts,
https://www.googleapis.com/auth/activity,
https://www.googleapis.com/auth/admin.datatransfer,
https://www.googleapis.com/auth/admin.directory.customer,
https://www.googleapis.com/auth/admin.directory.device.chromeos,
https://www.googleapis.com/auth/admin.directory.device.mobile,
https://www.googleapis.com/auth/admin.directory.domain,
https://www.googleapis.com/auth/admin.directory.group,
https://www.googleapis.com/auth/admin.directory.orgunit,
https://www.googleapis.com/auth/admin.directory.resource.calendar,
https://www.googleapis.com/auth/admin.directory.rolemanagement,
https://www.googleapis.com/auth/admin.directory.rolemanagement.readonly,
https://www.googleapis.com/auth/admin.directory.user,
https://www.googleapis.com/auth/admin.directory.user.readonly,
https://www.googleapis.com/auth/admin.directory.user.security,
https://www.googleapis.com/auth/admin.directory.userschema,
https://www.googleapis.com/auth/admin.reports.audit.readonly,
https://www.googleapis.com/auth/admin.reports.usage.readonly,
https://www.googleapis.com/auth/apps.groups.settings,
https://www.googleapis.com/auth/apps.licensing,
https://www.googleapis.com/auth/calendar,
https://www.googleapis.com/auth/chat.bot,
https://www.googleapis.com/auth/classroom.announcements,
https://www.googleapis.com/auth/classroom.courses,
https://www.googleapis.com/auth/classroom.coursework.me,
https://www.googleapis.com/auth/classroom.coursework.students,
https://www.googleapis.com/auth/classroom.guardianlinks.students,
https://www.googleapis.com/auth/classroom.profile.emails,
https://www.googleapis.com/auth/classroom.profile.photos,
https://www.googleapis.com/auth/classroom.push-notifications,
https://www.googleapis.com/auth/classroom.rosters,
https://www.googleapis.com/auth/classroom.rosters.readonly,
https://www.googleapis.com/auth/drive,
https://www.googleapis.com/auth/gmail.settings.basic,
https://www.googleapis.com/auth/gmail.settings.sharing,
https://www.googleapis.com/auth/plus.login,
https://www.googleapis.com/auth/plus.me,
https://www.googleapis.com/auth/tasks,
https://www.googleapis.com/auth/tasks.readonly,
https://www.googleapis.com/auth/userinfo.email,
https://www.googleapis.com/auth/userinfo.profile
Manage Google G Suite with PowerShell
Install PSGSuite & Configuration Modules
Install-Module Configuration
Install-Module -Name PSGSuite -RequiredVersion 2.24.0
#Import PSGSuite Module
Import-Module PSGSuite
PSGSuite Configuration File
Prepare the PSGSuite Configuration File with all the information gathered from Google G Suite and Developer Console
$ConfigName = "GSuite"
$P12KeyPath = "C:\GSuite\psgsuite-284106-f422e66d3841.p12"
$AppEmail = "[email protected]"
$AdminEmail = "[email protected]"
$CustomerID = "03xxxxxx"
$Domain = "aventislab.info"
$ServiceAccountClientID = "10745224254xxxxxxxxx"
Set-PSGSuiteConfig -ConfigName $ConfigName `
-P12KeyPath $P12KeyPath -AppEmail $AppEmail `
-AdminEmail $AdminEmail -CustomerID $CustomerID `
-Domain $Domain -ServiceAccountClientID $ServiceAccountClientID
Obtain your Customer ID via https://admin.google.com/ac/accountsettings/profile
List all users provisioned in G Suite with Get-GSUserList
Get-GSUserList | Select User
User
----
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Export Existing Users & Groups
List all existing users in G Suite and export to CSV file
$Users = Get-GSUserList
foreach ($User in $Users) {
$user | Select User,
@{N="FamilyName" ; E={($_.Name.familyname)}},
@{N="GivenName" ; E={($_.Name.GivenName)}}, PrimaryEmail | Export-Csv C:\Temp\UserList.csv -NoTypeInformation -Append
}
Output
User FamilyName GivenName PrimaryEmail
---- ---------- --------- ------------
[email protected] Kam Wah Yong [email protected]
[email protected] TEST UAT1 [email protected]
[email protected] TEST UAT2 [email protected]
[email protected] TEST UAT3 [email protected]
Export all existing group and memberships and export to CSV file
$Groups = Get-GSGroup
foreach ($Group in $Groups) {
Get-GSGroupMember -Identity $Group.Name | Select Group, Email, Role | Export-Csv C:\Temp\GroupList.csv -NoTypeInformation -Append
}
Output
Group Email Role
----- ----- ----
[email protected] [email protected] OWNER
[email protected] [email protected] MEMBER
[email protected] [email protected] OWNER
[email protected] [email protected] MEMBER
Appendix
Commands Available in PSGSuite Module
Get-Command -Module PSGSuite
CommandType Name Version Source
----------- ---- ------- ------
Alias Add-GSDriveFilePermissions 2.24.0 PSGSuite
Alias Export-PSGSuiteConfiguration 2.24.0 PSGSuite
Alias Get-GSCalendarEventList 2.24.0 PSGSuite
Alias Get-GSCalendarResourceList 2.24.0 PSGSuite
Alias Get-GSDataTransferApplicationList 2.24.0 PSGSuite
Alias Get-GSDriveFileInfo 2.24.0 PSGSuite
Alias Get-GSDriveFilePermissionsList 2.24.0 PSGSuite
Alias Get-GSGmailDelegates 2.24.0 PSGSuite
Alias Get-GSGmailFilterList 2.24.0 PSGSuite
Alias Get-GSGmailLabelList 2.24.0 PSGSuite
Alias Get-GSGmailMessageInfo 2.24.0 PSGSuite
Alias Get-GSGmailSendAsSettings 2.24.0 PSGSuite
Alias Get-GSGmailSignature 2.24.0 PSGSuite
Alias Get-GSGroupList 2.24.0 PSGSuite
Alias Get-GSGroupMemberList 2.24.0 PSGSuite
Alias Get-GSMobileDeviceList 2.24.0 PSGSuite
Alias Get-GSOrganizationalUnitList 2.24.0 PSGSuite
Alias Get-GSOrgUnit 2.24.0 PSGSuite
Alias Get-GSOrgUnitList 2.24.0 PSGSuite
Alias Get-GSOU 2.24.0 PSGSuite
Alias Get-GSResourceList 2.24.0 PSGSuite
Alias Get-GSShortURLInfo 2.24.0 PSGSuite
Alias Get-GSTeamDrivesList 2.24.0 PSGSuite
Alias Get-GSUserASPList 2.24.0 PSGSuite
Alias Get-GSUserLicenseInfo 2.24.0 PSGSuite
Alias Get-GSUserLicenseList 2.24.0 PSGSuite
Alias Get-GSUserList 2.24.0 PSGSuite
Alias Get-GSUserSchemaInfo 2.24.0 PSGSuite
Alias Get-GSUserSchemaList 2.24.0 PSGSuite
Alias Get-GSUserTokenList 2.24.0 PSGSuite
Alias Import-PSGSuiteConfiguration 2.24.0 PSGSuite
Alias Move-GSGmailMessageToTrash 2.24.0 PSGSuite
Alias New-GSCalendarResource 2.24.0 PSGSuite
Alias Remove-GSGmailMessageFromTrash 2.24.0 PSGSuite
Alias Set-PSGSuiteDefaultDomain 2.24.0 PSGSuite
Alias Switch-PSGSuiteDomain 2.24.0 PSGSuite
Alias Update-GSCalendarResource 2.24.0 PSGSuite
Alias Update-GSGmailSendAsSettings 2.24.0 PSGSuite
Alias Update-GSSheetValue 2.24.0 PSGSuite
Function Add-GSCalendarSubscription 2.24.0 PSGSuite
Function Add-GSChatButton 2.24.0 PSGSuite
Function Add-GSChatCard 2.24.0 PSGSuite
Function Add-GSChatCardAction 2.24.0 PSGSuite
Function Add-GSChatCardSection 2.24.0 PSGSuite
Function Add-GSChatImage 2.24.0 PSGSuite
Function Add-GSChatKeyValue 2.24.0 PSGSuite
Function Add-GSChatOnClick 2.24.0 PSGSuite
Function Add-GSChatTextParagraph 2.24.0 PSGSuite
Function Add-GSCourseParticipant 2.24.0 PSGSuite
Function Add-GSDocContent 2.24.0 PSGSuite
Function Add-GSDrivePermission 2.24.0 PSGSuite
Function Add-GSEventAttendee 2.24.0 PSGSuite
Function Add-GSGmailDelegate 2.24.0 PSGSuite
Function Add-GSGmailFilter 2.24.0 PSGSuite
Function Add-GSGmailForwardingAddress 2.24.0 PSGSuite
Function Add-GSGmailSmtpMsa 2.24.0 PSGSuite
Function Add-GSGroupMember 2.24.0 PSGSuite
Function Add-GSPrincipalGroupMembership 2.24.0 PSGSuite
Function Add-GSUserAddress 2.24.0 PSGSuite
Function Add-GSUserEmail 2.24.0 PSGSuite
Function Add-GSUserExternalId 2.24.0 PSGSuite
Function Add-GSUserOrganization 2.24.0 PSGSuite
Function Add-GSUserPhone 2.24.0 PSGSuite
Function Add-GSUserRelation 2.24.0 PSGSuite
Function Add-GSUserSchemaField 2.24.0 PSGSuite
Function Block-CoreCLREncryptionWarning 2.24.0 PSGSuite
Function Clear-GSSheet 2.24.0 PSGSuite
Function Clear-GSTasklist 2.24.0 PSGSuite
Function Compare-ModuleVersion 2.24.0 PSGSuite
Function Confirm-GSCourseInvitation 2.24.0 PSGSuite
Function Copy-GSDriveFile 2.24.0 PSGSuite
Function Copy-GSSheet 2.24.0 PSGSuite
Function Export-GSDriveFile 2.24.0 PSGSuite
Function Export-GSSheet 2.24.0 PSGSuite
Function Export-PSGSuiteConfig 2.24.0 PSGSuite
Function Get-GSActivityReport 2.24.0 PSGSuite
Function Get-GSAdminRole 2.24.0 PSGSuite
Function Get-GSAdminRoleAssignment 2.24.0 PSGSuite
Function Get-GSCalendarACL 2.24.0 PSGSuite
Function Get-GSCalendarEvent 2.24.0 PSGSuite
Function Get-GSCalendarSubscription 2.24.0 PSGSuite
Function Get-GSChatConfig 2.24.0 PSGSuite
Function Get-GSChatMember 2.24.0 PSGSuite
Function Get-GSChatMessage 2.24.0 PSGSuite
Function Get-GSChatSpace 2.24.0 PSGSuite
Function Get-GSChromeOSDevice 2.24.0 PSGSuite
Function Get-GSClassroomUserProfile 2.24.0 PSGSuite
Function Get-GSContactList 2.24.0 PSGSuite
Function Get-GSCourse 2.24.0 PSGSuite
Function Get-GSCourseAlias 2.24.0 PSGSuite
Function Get-GSCourseInvitation 2.24.0 PSGSuite
Function Get-GSCourseParticipant 2.24.0 PSGSuite
Function Get-GSDataTransferApplication 2.24.0 PSGSuite
Function Get-GSDocContent 2.24.0 PSGSuite
Function Get-GSDriveFile 2.24.0 PSGSuite
Function Get-GSDriveFileList 2.24.0 PSGSuite
Function Get-GSDriveFileUploadStatus 2.24.0 PSGSuite
Function Get-GSDrivePermission 2.24.0 PSGSuite
Function Get-GSDriveProfile 2.24.0 PSGSuite
Function Get-GSGmailAutoForwardingSettings 2.24.0 PSGSuite
Function Get-GSGmailDelegate 2.24.0 PSGSuite
Function Get-GSGmailFilter 2.24.0 PSGSuite
Function Get-GSGmailForwardingAddress 2.24.0 PSGSuite
Function Get-GSGmailImapSettings 2.24.0 PSGSuite
Function Get-GSGmailLabel 2.24.0 PSGSuite
Function Get-GSGmailMessage 2.24.0 PSGSuite
Function Get-GSGmailMessageList 2.24.0 PSGSuite
Function Get-GSGmailPopSettings 2.24.0 PSGSuite
Function Get-GSGmailProfile 2.24.0 PSGSuite
Function Get-GSGmailSendAsAlias 2.24.0 PSGSuite
Function Get-GSGmailSMIMEInfo 2.24.0 PSGSuite
Function Get-GSGmailVacationSettings 2.24.0 PSGSuite
Function Get-GSGroup 2.24.0 PSGSuite
Function Get-GSGroupAlias 2.24.0 PSGSuite
Function Get-GSGroupMember 2.24.0 PSGSuite
Function Get-GSGroupSettings 2.24.0 PSGSuite
Function Get-GSMobileDevice 2.24.0 PSGSuite
Function Get-GSOrganizationalUnit 2.24.0 PSGSuite
Function Get-GSResource 2.24.0 PSGSuite
Function Get-GSSheetInfo 2.24.0 PSGSuite
Function Get-GSShortUrl 2.24.0 PSGSuite
Function Get-GSStudentGuardian 2.24.0 PSGSuite
Function Get-GSStudentGuardianInvitation 2.24.0 PSGSuite
Function Get-GSTask 2.24.0 PSGSuite
Function Get-GSTasklist 2.24.0 PSGSuite
Function Get-GSTeamDrive 2.24.0 PSGSuite
Function Get-GSToken 2.24.0 PSGSuite
Function Get-GSUsageReport 2.24.0 PSGSuite
Function Get-GSUser 2.24.0 PSGSuite
Function Get-GSUserAlias 2.24.0 PSGSuite
Function Get-GSUserASP 2.24.0 PSGSuite
Function Get-GSUserLicense 2.24.0 PSGSuite
Function Get-GSUserPhoto 2.24.0 PSGSuite
Function Get-GSUserSchema 2.24.0 PSGSuite
Function Get-GSUserToken 2.24.0 PSGSuite
Function Get-GSUserVerificationCodes 2.24.0 PSGSuite
Function Get-PSGSuiteConfig 2.24.0 PSGSuite
Function Import-GSSheet 2.24.0 PSGSuite
Function Import-PSGSuiteConfig 2.24.0 PSGSuite
Function Move-GSTask 2.24.0 PSGSuite
Function New-GoogleService 2.24.0 PSGSuite
Function New-GSAdminRole 2.24.0 PSGSuite
Function New-GSAdminRoleAssignment 2.24.0 PSGSuite
Function New-GSCalendarACL 2.24.0 PSGSuite
Function New-GSCalendarEvent 2.24.0 PSGSuite
Function New-GSCourse 2.24.0 PSGSuite
Function New-GSCourseAlias 2.24.0 PSGSuite
Function New-GSCourseInvitation 2.24.0 PSGSuite
Function New-GSDriveFile 2.24.0 PSGSuite
Function New-GSGmailLabel 2.24.0 PSGSuite
Function New-GSGmailSendAsAlias 2.24.0 PSGSuite
Function New-GSGmailSMIMEInfo 2.24.0 PSGSuite
Function New-GSGroup 2.24.0 PSGSuite
Function New-GSGroupAlias 2.24.0 PSGSuite
Function New-GSOrganizationalUnit 2.24.0 PSGSuite
Function New-GSResource 2.24.0 PSGSuite
Function New-GSSheet 2.24.0 PSGSuite
Function New-GSShortUrl 2.24.0 PSGSuite
Function New-GSStudentGuardianInvitation 2.24.0 PSGSuite
Function New-GSTask 2.24.0 PSGSuite
Function New-GSTasklist 2.24.0 PSGSuite
Function New-GSTeamDrive 2.24.0 PSGSuite
Function New-GSUser 2.24.0 PSGSuite
Function New-GSUserAlias 2.24.0 PSGSuite
Function New-GSUserSchema 2.24.0 PSGSuite
Function New-GSUserVerificationCodes 2.24.0 PSGSuite
Function Remove-GSAdminRole 2.24.0 PSGSuite
Function Remove-GSAdminRoleAssignment 2.24.0 PSGSuite
Function Remove-GSCalendarEvent 2.24.0 PSGSuite
Function Remove-GSCalendarSubscription 2.24.0 PSGSuite
Function Remove-GSChatMessage 2.24.0 PSGSuite
Function Remove-GSContact 2.24.0 PSGSuite
Function Remove-GSCourse 2.24.0 PSGSuite
Function Remove-GSCourseAlias 2.24.0 PSGSuite
Function Remove-GSCourseInvitation 2.24.0 PSGSuite
Function Remove-GSCourseParticipant 2.24.0 PSGSuite
Function Remove-GSDriveFile 2.24.0 PSGSuite
Function Remove-GSDrivePermission 2.24.0 PSGSuite
Function Remove-GSGmailDelegate 2.24.0 PSGSuite
Function Remove-GSGmailFilter 2.24.0 PSGSuite
Function Remove-GSGmailLabel 2.24.0 PSGSuite
Function Remove-GSGmailMessage 2.24.0 PSGSuite
Function Remove-GSGmailSendAsAlias 2.24.0 PSGSuite
Function Remove-GSGmailSMIMEInfo 2.24.0 PSGSuite
Function Remove-GSGroup 2.24.0 PSGSuite
Function Remove-GSGroupAlias 2.24.0 PSGSuite
Function Remove-GSGroupMember 2.24.0 PSGSuite
Function Remove-GSMobileDevice 2.24.0 PSGSuite
Function Remove-GSOrganizationalUnit 2.24.0 PSGSuite
Function Remove-GSPrincipalGroupMembership 2.24.0 PSGSuite
Function Remove-GSResource 2.24.0 PSGSuite
Function Remove-GSStudentGuardian 2.24.0 PSGSuite
Function Remove-GSTask 2.24.0 PSGSuite
Function Remove-GSTasklist 2.24.0 PSGSuite
Function Remove-GSTeamDrive 2.24.0 PSGSuite
Function Remove-GSUser 2.24.0 PSGSuite
Function Remove-GSUserAlias 2.24.0 PSGSuite
Function Remove-GSUserASP 2.24.0 PSGSuite
Function Remove-GSUserLicense 2.24.0 PSGSuite
Function Remove-GSUserPhoto 2.24.0 PSGSuite
Function Remove-GSUserSchema 2.24.0 PSGSuite
Function Remove-GSUserToken 2.24.0 PSGSuite
Function Restore-GSGmailMessage 2.24.0 PSGSuite
Function Restore-GSUser 2.24.0 PSGSuite
Function Revoke-GSStudentGuardianInvitation 2.24.0 PSGSuite
Function Revoke-GSUserVerificationCodes 2.24.0 PSGSuite
Function Send-GmailMessage 2.24.0 PSGSuite
Function Send-GSChatMessage 2.24.0 PSGSuite
Function Send-GSGmailSendAsConfirmation 2.24.0 PSGSuite
Function Set-GSDocContent 2.24.0 PSGSuite
Function Set-GSGroupSettings 2.24.0 PSGSuite
Function Set-GSUserLicense 2.24.0 PSGSuite
Function Set-GSUserSchema 2.24.0 PSGSuite
Function Set-PSGSuiteConfig 2.24.0 PSGSuite
Function Show-PSGSuiteConfig 2.24.0 PSGSuite
Function Start-GSDataTransfer 2.24.0 PSGSuite
Function Start-GSDriveFileUpload 2.24.0 PSGSuite
Function Stop-GSDriveFileUpload 2.24.0 PSGSuite
Function Switch-PSGSuiteConfig 2.24.0 PSGSuite
Function Sync-GSUserCache 2.24.0 PSGSuite
Function Unblock-CoreCLREncryptionWarning 2.24.0 PSGSuite
Function Update-GSAdminRole 2.24.0 PSGSuite
Function Update-GSCalendarEvent 2.24.0 PSGSuite
Function Update-GSChatMessage 2.24.0 PSGSuite
Function Update-GSChromeOSDevice 2.24.0 PSGSuite
Function Update-GSCourse 2.24.0 PSGSuite
Function Update-GSDriveFile 2.24.0 PSGSuite
Function Update-GSGmailAutoForwardingSettings 2.24.0 PSGSuite
Function Update-GSGmailImapSettings 2.24.0 PSGSuite
Function Update-GSGmailLabel 2.24.0 PSGSuite
Function Update-GSGmailMessageLabels 2.24.0 PSGSuite
Function Update-GSGmailPopSettings 2.24.0 PSGSuite
Function Update-GSGmailSendAsAlias 2.24.0 PSGSuite
Function Update-GSGmailSignature 2.24.0 PSGSuite
Function Update-GSGmailVacationSettings 2.24.0 PSGSuite
Function Update-GSGroupMember 2.24.0 PSGSuite
Function Update-GSGroupSettings 2.24.0 PSGSuite
Function Update-GSMobileDevice 2.24.0 PSGSuite
Function Update-GSOrganizationalUnit 2.24.0 PSGSuite
Function Update-GSResource 2.24.0 PSGSuite
Function Update-GSTask 2.24.0 PSGSuite
Function Update-GSTasklist 2.24.0 PSGSuite
Function Update-GSTeamDrive 2.24.0 PSGSuite
Function Update-GSUser 2.24.0 PSGSuite
Function Update-GSUserLicense 2.24.0 PSGSuite
Function Update-GSUserPhoto 2.24.0 PSGSuite
Function Update-GSUserSchema 2.24.0 PSGSuite
Function Watch-GSDriveUpload 2.24.0 PSGSuite