Get-O365DLConfiguration.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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
<#
.SYNOPSIS This function uses the exchange online powershell session to gather the office 365 distribution list configuration. .DESCRIPTION This function uses the exchange online powershell session to gather the office 365 distribution list configuration. .PARAMETER GroupSMTPAddress The mail attribute of the group to search. .OUTPUTS Returns the PS object associated with the recipient from get-o365recipient .EXAMPLE get-o365dlconfiguration -groupSMTPAddress Address -groupTypeOverride #> Function Get-o365DLConfiguration { [cmdletbinding()] Param ( [Parameter(Mandatory = $true)] [string]$groupSMTPAddress, [Parameter(Mandatory = $false)] [string]$groupTypeOverride="", [Parameter(Mandatory = $false)] [boolean]$isUnifiedGroup=$false, [Parameter(Mandatory = $false)] [boolean]$isFirstPass=$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. $functionDLConfiguration=$NULL #Holds the return information for the group query. $functionMailSecurity="MailUniversalSecurityGroup" $functionMailDistribution="MailUniversalDistributionGroup" $functionGroupType = "GroupMailbox" #Start function processing. Out-LogFile -string "********************************************************************************" Out-LogFile -string "BEGIN GET-O365DLCONFIGURATION" Out-LogFile -string "********************************************************************************" #Get the recipient using the exchange online powershell session. $functionRecipient = get-o365Recipient -identity $groupSMTPAddress out-logfile -string $functionRecipient out-logfile -string "Testing if this is the first pass for DL validation." if ($isFirstPass -eq $TRUE) { out-logfile -string "This is the first pass." if ($functionRecipient.RecipientTypeDetails -eq $functionGroupType) { out-logfile -string "Office 365 Recipient found is already an Office 365 Unified Group - exit." -isError:$TRUE } elseif (($functionRecipient.RecipientType -ne $functionMailSecurity) -and ($functionRecipient.RecipientType -ne $functionMailDistribution)) { out-logfile -string "Office 365 Recipient found was not a mail univeral distribution or mail universal security group - exit." -isError:$TRUE } else { out-logfile -string "Proceed with further group evaluation - group object located in Office 365." } } else { out-logfile -string "This is not the first pass." } if (($isUnifiedGroup -eq $false) -and ($functionRecipient.recipientTypeDetails -ne $functionGroupType)) { out-logfile -string "Group is not unified use standard DL commands." try { if ($groupTypeOverride -eq "") { Out-LogFile -string "Using Exchange Online to capture the distribution group." $functionDLConfiguration=get-O365DistributionGroup -identity $groupSMTPAddress -errorAction STOP Out-LogFile -string "Original DL configuration found and recorded." } elseif ($groupTypeOverride -eq "Security") { Out-logfile -string "Using Exchange Online to capture distribution group with filter security" $functionDLConfiguration=get-o365DistributionGroup -identity $groupSMTPAddress -RecipientTypeDetails $functionMailSecurity -errorAction STOP out-logfile -string "Original DL configuration found and recorded by filter security." } elseif ($groupTypeOverride -eq "Distribution") { out-logfile -string "Using Exchange Online to capture distribution group with filter distribution." $functionDLConfiguration=get-o365DistributionGroup -identity $groupSMTPAddress -RecipientTypeDetails $functionMailDistribution out-logfile -string "Original DL configuration found and recorded by filter distribution." } } catch { Out-LogFile -string $_ -isError:$TRUE } } else { out-logfile -string "Group is unified use unified group commands." try { $functionDLConfiguration = get-o365UnifiedGroup -identity $groupSMTPAddress -includeAllProperties -errorAction STOP } catch { out-logfile -string $_ -isError:$TRUE } } Out-LogFile -string "END GET-O365DLCONFIGURATION" Out-LogFile -string "********************************************************************************" #This function is designed to open local and remote powershell sessions. #If the session requires import - for example exchange - return the session for later work. #If not no return is required. return $functionDLConfiguration } |