-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGet-AzureADMembership.ps1
91 lines (65 loc) · 2.9 KB
/
Get-AzureADMembership.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<#
.SYNOPSIS
This function obtains the DL membership of the Office 365 distribution group.
.DESCRIPTION
This function obtains the DL membership of the Office 365 distribution group.
.PARAMETER GroupObjectID
The Object ID to obtain membership values from Azure.
.OUTPUTS
Returns the membership array of the DL in Office 365.
.EXAMPLE
get-o365dlMembership -groupSMTPAddress Address
#>
Function Get-AzureADMembership
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
[string]$groupObjectID,
[Parameter(Mandatory = $false)]
[boolean]$isHealthReport=$false
)
#Output all parameters bound or unbound and their associated values.
write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore)
#Declare function variables.
$functionDLMembership=$NULL #Holds the return information for the group query.
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN GET-AZUREADMEMBERSHIP"
Out-LogFile -string "********************************************************************************"
#Get the recipient using the exchange online powershell session.
out-logfile -string "Attempting to obtain the Azure AD Group membership."
if ($isHealthReport -eq $FALSE)
{
try {
$functionDLMembership = get-azureADGroupMember -objectID $groupobjectID -all:$TRUE -errorAction STOP
}
catch {
out-logfile -string "Unable to obtain the azure group membership."
out-logfile -string $_ -isError:$TRUE
}
}
else
{
try {
$functionDLMembership = get-azureADGroupMember -objectID $groupobjectID -all:$TRUE -errorAction STOP | select-object objectID,objectType,mail,mailnickname,onPremisesSecurityIdentifier,proxyAddresses,userPrincipalName,userType,provisioningErrors
}
catch {
out-logfile -string "Unable to obtain the azure group membership."
out-logfile -string $_ -isError:$TRUE
}
}
if ($functionDLMembership.count -gt 0)
{
out-logfile -string $functionDLMembership
}
else
{
out-logfile -string "No Azure AD Group members in the specified group."
}
Out-LogFile -string "END GET-AZUREADMEMBERSHIP"
Out-LogFile -string "********************************************************************************"
#Return the membership to the caller.
return $functionDLMembership
}