Functions/Get-GSuiteGroupMember.ps1
<#
.SYNOPSIS This function gets the members of a GSuite group. This function returns either PSCustomObject when there is one member, or Object[] when there is more than one member. #> function Get-GSuiteGroupMember { [CmdletBinding(PositionalBinding=$false)] [OutputType([Object[]], [PSCustomObject])] param ( # The primary email address of the group. [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$primaryEmailAddress ) # Validate that the 'connection' has been established if (!$Global:GSuiteAccessTokensHashTable) { throw "You must call the Connect-GSuiteAdminAccount cmdlet before calling any other GSuite cmdlets." } # Validate that the group access token exists in the hash table if ([String]::IsNullOrWhiteSpace($Global:GSuiteAccessTokensHashTable.Group)) { throw "Group access token is required to call Get-GSuiteGroupMember." } # Prepare REST call parameters $invokeRestMethodParams = @{ Uri = "https://www.googleapis.com/admin/directory/v1/groups/$($primaryEmailAddress)/members" Method = "GET" Headers = @{ Accept = "application/json" Authorization = "Bearer $($Global:GSuiteAccessTokensHashTable.Group)" } } # Invoke the REST call $response = Invoke-RestMethod @invokeRestMethodParams return $response.members } |