Public/Users/Get-GSUserAlias.ps1
function Get-GSUserAlias { <# .SYNOPSIS Gets the specified G SUite User's aliases .DESCRIPTION Gets the specified G SUite User's aliases .PARAMETER User The primary email or UserID of the user who you are trying to get aliases for. You can exclude the '@domain.com' to insert the Domain in the config or use the special 'me' to indicate the AdminEmail in the config. Defaults to the AdminEmail in the config .EXAMPLE Get-GSUserAlias Gets the list of aliases for the AdminEmail user #> [cmdletbinding()] Param ( [parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String[]] $User = $Script:PSGSuite.AdminEmail ) Begin { $serviceParams = @{ Scope = 'https://www.googleapis.com/auth/admin.directory.user.readonly' ServiceType = 'Google.Apis.Admin.Directory.directory_v1.DirectoryService' } $service = New-GoogleService @serviceParams } Process { foreach ($U in $User) { try { if ($U -ceq 'me') { $U = $Script:PSGSuite.AdminEmail } elseif ($U -notlike "*@*.*") { $U = "$($U)@$($Script:PSGSuite.Domain)" } Write-Verbose "Getting Alias list for User '$U'" $request = $service.Users.Aliases.List($U) $request.Execute() | Select-Object -ExpandProperty AliasesValue } catch { if ($ErrorActionPreference -eq 'Stop') { $PSCmdlet.ThrowTerminatingError($_) } else { Write-Error $_ } } } } } |