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 and the group access token exists Assert-GSuiteConnection -Scope "Group" # 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 } |