From 439576a22ee575abc8886f2b194ee1cf844817fe Mon Sep 17 00:00:00 2001 From: hazemembaby <71065889+hazemembaby@users.noreply.github.com> Date: Sun, 15 Aug 2021 16:55:35 +0200 Subject: [PATCH 1/2] Merge branch 'main' of https://github.com/microsoft/CSS-Exchange --- M365/README.md | 4 +-- M365/src/DLT365Groupsupgrade.ps1 | 59 ++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/M365/README.md b/M365/README.md index 1cc20a2d06..c1309e8c28 100644 --- a/M365/README.md +++ b/M365/README.md @@ -1,8 +1,8 @@ # [DLT365Groupsupgrade.ps1](https://github.com/microsoft/CSS-Exchange/releases/latest/download/DLT365Groupsupgrade.ps1) -## Validating Distribution group eligibility for upgrade to O365 Group +## Validating Distribution group eligibility for upgrade to Microsoft 365 Group -This script allows you to check Distribution to O365 Group migration eligibility for a specific distribution group SMTP, for more information over the Distribution to O365 Group migration blockers please check: https://docs.microsoft.com/en-us/microsoft-365/admin/manage/upgrade-distribution-lists?view=o365-worldwide +This script allows you to check Distribution to Microsoft 365 Group migration eligibility for a specific distribution group SMTP, for more information over the Distribution to Microsoft 365 Group migration blockers please check: https://docs.microsoft.com/en-us/microsoft-365/admin/manage/upgrade-distribution-lists?view=o365-worldwide Download the latest release here: [https://github.com/microsoft/CSS-Exchange/releases/latest/download/DLT365Groupsupgrade.ps1](https://github.com/microsoft/CSS-Exchange/releases/latest/download/DLT365Groupsupgrade.ps1) diff --git a/M365/src/DLT365Groupsupgrade.ps1 b/M365/src/DLT365Groupsupgrade.ps1 index 45cf764a8b..9b9573fdaf 100644 --- a/M365/src/DLT365Groupsupgrade.ps1 +++ b/M365/src/DLT365Groupsupgrade.ps1 @@ -46,7 +46,7 @@ Function Connect2EXO { } else { #log failure and try to install EXO V2 module then Connect to EXO Write-Host "ExchangeOnlineManagement Powershell Module is missing `n Trying to install the module" -ForegroundColor Red - Install-Module -Name ExchangeOnlineManagement -Force -ErrorAction Stop + Install-Module -Name ExchangeOnlineManagement -Force -ErrorAction Stop -Scope CurrentUser Import-Module ExchangeOnlineManagement -ErrorAction stop -Force $CurrentDescription = "Installing & Importing EXO V2 powershell module" $CurrentStatus = "Success" @@ -100,13 +100,13 @@ Function Debugmatchingeap { $eap = Get-EmailAddressPolicy -ErrorAction stop # Bypass that step if there's no EAP if ($null -ne $eap) { - $matchingEap = @( $eap | Where-Object { $_.RecipientFilter -eq "RecipientTypeDetails -eq 'GroupMailbox'" -and $_.EnabledPrimarySMTPAddressTemplate.ToString().Split("@")[1] -ne $Distgroup.PrimarySmtpAddress.ToString().Split("@")[1] }) + $matchingEap = @( $eap | Where-Object { $_.RecipientFilter -eq "RecipientTypeDetails -eq 'GroupMailbox'" -and $_.EnabledPrimarySMTPAddressTemplate.ToString().Split("@")[1] -cne $Distgroup.PrimarySmtpAddress.ToString().Split("@")[1] }) if ($matchingEap.Count -ge 1) { $script:Conditionsfailed++ - Write-Host "Distribution Group can't be upgraded because Admin has applied Group Email Address Policy for the groups on the organization" -ForegroundColor Red + Write-Host "Distribution Group can't be upgraded because Admin has applied Group Email Address Policy for the groups on the organization e.g. DL PrimarySmtpAddress @Contoso.com while the EAP EnabledPrimarySMTPAddressTemplate is @contoso.com OR DL PrimarySmtpAddress @contoso.com however there's an EAP with EnabledPrimarySMTPAddressTemplate set to @fabrikam.com" -ForegroundColor Red Write-Host "Group Email Address Policy found:" -BackgroundColor Yellow -ForegroundColor Black $matchingEap | Format-Table name, recipientfilter, Guid, enabledemailaddresstemplates - "Distribution Group can't be upgraded because Admin has applied Group Email Address Policy for the groups on the organization" | Out-File $ExportPath\DlToO365GroupUpgradeChecksREPORT.txt -Append + "Distribution Group can't be upgraded because Admin has applied Group Email Address Policy for the groups on the organization e.g. DL PrimarySmtpAddress @Contoso.com while the EAP EnabledPrimarySMTPAddressTemplate is @contoso.com OR DL PrimarySmtpAddress @contoso.com however there's an EAP with EnabledPrimarySMTPAddressTemplate set to @fabrikam.com" | Out-File $ExportPath\DlToO365GroupUpgradeChecksREPORT.txt -Append "Group Email Address Policy found:" | Out-File $ExportPath\DlToO365GroupUpgradeChecksREPORT.txt -Append $matchingEap | Format-Table name, recipientfilter, Guid, enabledemailaddresstemplates | Out-File $ExportPath\DlToO365GroupUpgradeChecksREPORT.txt -Append } @@ -121,9 +121,9 @@ Function Debuggroupnesting { $ParentDGroups = @() try { $alldgs = Get-DistributionGroup -ResultSize unlimited -ErrorAction Stop - $CurrentDescription = "Retrieving All DGs in the EXO directory" - $CurrentStatus = "Success" - log -Function "Retrieve All DGs" -CurrentDescription $CurrentDescription -CurrentStatus $CurrentStatus + #$CurrentDescription = "Retrieving All DGs in the EXO directory" + #$CurrentStatus = "Success" + #log -Function "Retrieve All DGs" -CurrentDescription $CurrentDescription -CurrentStatus $CurrentStatus } catch { $CurrentDescription = "Retrieving All DGs in the EXO directory" $CurrentStatus = "Failure" @@ -132,9 +132,9 @@ Function Debuggroupnesting { foreach ($parentdg in $alldgs) { try { $Pmembers = Get-DistributionGroupMember $($parentdg.Guid.ToString()) -ErrorAction Stop - $CurrentDescription = "Retrieving: $parentdg members" - $CurrentStatus = "Success" - log -Function "Retrieve Distribution Group membership" -CurrentDescription $CurrentDescription -CurrentStatus $CurrentStatus + #$CurrentDescription = "Retrieving: $parentdg members" + #$CurrentStatus = "Success" + #log -Function "Retrieve Distribution Group membership" -CurrentDescription $CurrentDescription -CurrentStatus $CurrentStatus } catch { $CurrentDescription = "Retrieving: $parentdg members" $CurrentStatus = "Failure" @@ -208,6 +208,44 @@ Function Debugownerscount { "Distribution Group can't be upgraded because it has more than 100 owners or it has no owners" | Out-File $ExportPath\DlToO365GroupUpgradeChecksREPORT.txt -Append } } +#Check if Distribution Group can't be upgraded because the distribution list owner(s) is non-supported with RecipientTypeDetails other than UserMailbox, MailUser +Function Debugownersstatus { + param( + [Parameter(Mandatory = $true)] + [PScustomobject]$Distgroup + ) + $owners = $Distgroup.ManagedBy + if ($owners.Count -le 100 -and $owners.Count -ge 1) { + $ConditionDGownerswithoutMBX = @() + foreach ($owner in $owners) { + try { + $owner = Get-Recipient $owner -ErrorAction stop + $CurrentDescription = "Validating: $owner RecipientTypeDetails" + $CurrentStatus = "Success" + log -Function "Validate owner RecipientTypeDetails" -CurrentStatus $CurrentStatus -CurrentDescription $CurrentDescription + if (!($owner.RecipientTypeDetails -eq "UserMailbox" -or $owner.RecipientTypeDetails -eq "MailUser")) { + $ConditionDGownerswithoutMBX = $ConditionDGownerswithoutMBX + $owner + } + } catch { + $CurrentDescription = "Validating: $owner RecipientTypeDetails" + $CurrentStatus = "Failure" + log -Function "Validate owner RecipientTypeDetails" -CurrentStatus $CurrentStatus -CurrentDescription $CurrentDescription + #Check if the owner RecipientTypeDetails is User + $owner = Get-User $owner -ErrorAction stop + $ConditionDGownerswithoutMBX = $ConditionDGownerswithoutMBX + $owner + } + } + if ($ConditionDGownerswithoutMBX.Count -ge 1) { + Write-Host "Distribution Group can't be upgraded because DL owner(s) is non-supported with RecipientTypeDetails other than UserMailbox, MailUser" -ForegroundColor Red + Write-Host "Non-supported Owner(s) found:" -BackgroundColor Yellow -ForegroundColor Black + $ConditionDGownerswithoutMBX | Format-Table -AutoSize -Wrap Name, GUID, RecipientTypeDetails + "Distribution Group can't be upgraded because DL owner(s) is non-supported with RecipientTypeDetails other than UserMailbox, MailUser" | Out-File $ExportPath\DlToO365GroupUpgradeChecksREPORT.txt -Append + "Non-supported Owner(s) found:" | Out-File $ExportPath\DlToO365GroupUpgradeChecksREPORT.txt -Append + $ConditionDGownerswithoutMBX | Format-Table -AutoSize -Wrap Name, GUID, RecipientTypeDetails | Out-File $ExportPath\DlToO365GroupUpgradeChecksREPORT.txt -Append + $script:Conditionsfailed++ + } + } +} #Check if Distribution Group can't be upgraded because the distribution list is part of Sender Restriction in another DL Function Debugsenderrestriction { param( @@ -377,6 +415,7 @@ Debugmatchingeap($dg) Debuggroupnesting($dg) DebugmembersrecipientTypes($dg) Debugownerscount($dg) +Debugownersstatus($dg) Debugsenderrestriction($dg) Debuggrouprecipienttype($dg) Debugforwardingforsharedmbxs($dg) From 11a710b0fa109ba7872a2deca330b0ace0819bd8 Mon Sep 17 00:00:00 2001 From: hazemembaby <71065889+hazemembaby@users.noreply.github.com> Date: Sun, 15 Aug 2021 19:39:37 +0200 Subject: [PATCH 2/2] remove commented lines --- M365/src/DLT365Groupsupgrade.ps1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/M365/src/DLT365Groupsupgrade.ps1 b/M365/src/DLT365Groupsupgrade.ps1 index 9b9573fdaf..6c5c4717a1 100644 --- a/M365/src/DLT365Groupsupgrade.ps1 +++ b/M365/src/DLT365Groupsupgrade.ps1 @@ -121,9 +121,9 @@ Function Debuggroupnesting { $ParentDGroups = @() try { $alldgs = Get-DistributionGroup -ResultSize unlimited -ErrorAction Stop - #$CurrentDescription = "Retrieving All DGs in the EXO directory" - #$CurrentStatus = "Success" - #log -Function "Retrieve All DGs" -CurrentDescription $CurrentDescription -CurrentStatus $CurrentStatus + $CurrentDescription = "Retrieving All DGs in the EXO directory" + $CurrentStatus = "Success" + log -Function "Retrieve All DGs" -CurrentDescription $CurrentDescription -CurrentStatus $CurrentStatus } catch { $CurrentDescription = "Retrieving All DGs in the EXO directory" $CurrentStatus = "Failure" @@ -132,9 +132,6 @@ Function Debuggroupnesting { foreach ($parentdg in $alldgs) { try { $Pmembers = Get-DistributionGroupMember $($parentdg.Guid.ToString()) -ErrorAction Stop - #$CurrentDescription = "Retrieving: $parentdg members" - #$CurrentStatus = "Success" - #log -Function "Retrieve Distribution Group membership" -CurrentDescription $CurrentDescription -CurrentStatus $CurrentStatus } catch { $CurrentDescription = "Retrieving: $parentdg members" $CurrentStatus = "Failure"