Skip to content

Commit

Permalink
Merge pull request #1874 from microsoft/main
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
bill-long authored Nov 6, 2023
2 parents 08b07c0 + 141355e commit 238eacb
Show file tree
Hide file tree
Showing 29 changed files with 954 additions and 451 deletions.
4 changes: 3 additions & 1 deletion .build/CodeFormatter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ param(
Set-StrictMode -Version Latest

. $PSScriptRoot\Load-Module.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckContainsCurlyQuotes.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckFileHasNewlineAtEndOfFile.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckMarkdownFileHasNoBOM.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckMultipleEmptyLines.ps1
Expand All @@ -23,7 +24,7 @@ Set-StrictMode -Version Latest
. $PSScriptRoot\CodeFormatterChecks\CheckScriptFormat.ps1
. $PSScriptRoot\HelpFunctions\Get-CommitFilesOnBranch.ps1

if (-not (Load-Module -Name PSScriptAnalyzer -MinimumVersion "1.20")) {
if (-not (Load-Module -Name PSScriptAnalyzer -MinimumVersion "1.21")) {
throw "PSScriptAnalyzer module could not be loaded"
}

Expand Down Expand Up @@ -69,6 +70,7 @@ foreach ($fileInfo in $filesToCheck) {
$errorCount += (CheckScriptFileHasComplianceHeader $fileInfo $Save) ? 1 : 0
$errorCount += (CheckKeywordCasing $fileInfo $Save) ? 1 : 0
$errorCount += (CheckMultipleEmptyLines $fileInfo $Save) ? 1 : 0
$errorCount += (CheckContainsCurlyQuotes $fileInfo $Save) ? 1 : 0

# This one is tricky. It returns $true or $false like the others, but in the case
# of an error, we also want to get the diff output. Piping to Out-Host from within
Expand Down
51 changes: 51 additions & 0 deletions .build/CodeFormatterChecks/CheckContainsCurlyQuotes.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

function CheckContainsCurlyQuotes {
[CmdletBinding()]
[OutputType([boolean])]
param (
[Parameter()]
[System.IO.FileInfo]
$FileInfo,

[Parameter()]
[boolean]
$Save
)

# Skip this file
if ($FileInfo.FullName -eq "$PSScriptRoot\CheckContainsCurlyQuotes.ps1") {
return $false
}

$curlyQuotes = $FileInfo | Select-String "‘|’|`“|`”"
if ($curlyQuotes) {
$content = Get-Content -Path $FileInfo.FullName -Raw
if ($Save) {
try {
$content = $content -replace "", "'"
$content = $content -replace "", "'"
$content = $content -replace "`“", '"'
$content = $content -replace "`”", '"'
if ($FileInfo.Extension -eq ".ps1") {
Set-Content -Path $FileInfo.FullName -Value $content.TrimEnd() -Encoding utf8BOM
} else {
Set-Content -Path $FileInfo.FullName -Value $content.TrimEnd() -Encoding utf8NoBOM
}

Write-Host "Saved with curly quotes replaced: $($FileInfo.FullName)"
$false
} catch {
Write-Warning "Failed to save with curly quotes replaced: $($FileInfo.FullName). Error: $_"
$true
}
} else {
Write-Warning "File contains curly quotes: $($FileInfo.FullName)"
$curlyQuotes | Out-Host
$true
}
} else {
$false
}
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@
"internal-terms": false // Disable the `internal-terms` dictionary
},
"cSpell.caseSensitive": true,
"editor.detectIndentation": false
"editor.detectIndentation": false,
"editor.unicodeHighlight.includeComments": true,
"editor.unicodeHighlight.nonBasicASCII": true
}
48 changes: 25 additions & 23 deletions Admin/CrossTenantMailboxMigrationValidation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ function CheckObjects {

#PrimarySMTP
Write-Verbose -Message "Informational: Checking if the PrimarySTMPAddress of TARGET belongs to a TARGET accepted domain"
if ($TargetTenantAcceptedDomains.DomainName -notcontains $TargetObject.PrimarySmtpAddress.Split('@')[1]) {
if ($TargetTenantAcceptedDomains.DomainName -contains $TargetObject.PrimarySmtpAddress.Split('@')[1]) {
Write-Host ">> Target MailUser PrimarySMTPAddress is part of target accepted domains" -ForegroundColor Green
} else {
Write-Host ">> Error: The Primary SMTP address $($TargetObject.PrimarySmtpAddress) of the MailUser does not belong to an accepted domain on the target tenant" -ForegroundColor Red -NoNewline
if (!$TargetObject.IsDirSynced) {
Write-Host ">> Error: The Primary SMTP address $($TargetObject.PrimarySmtpAddress) of the MailUser does not belong to an accepted domain on the target tenant, would you like to set it to $($TargetObject.UserPrincipalName) (Y/N): " -ForegroundColor Red -NoNewline
Write-Host ">> would you like to set it to $($TargetObject.UserPrincipalName) (Y/N): " -ForegroundColor Red -NoNewline
$PrimarySMTPAddressSetOption = Read-Host
Write-Host " Your input: $($PrimarySMTPAddressSetOption)"
if ($PrimarySMTPAddressSetOption.ToLower() -eq "y") {
Expand All @@ -378,15 +381,15 @@ function CheckObjects {
} else {
Write-Host ">> Error: The Primary SMTP address $($TargetObject.PrimarySmtpAddress) of the MailUser does not belong to an accepted domain on the target tenant. The object is DirSynced and this is not a change that can be done directly on EXO. Please do the change on-premises and perform an AADConnect delta sync" -ForegroundColor Red
}
} else {
Write-Host ">> Target MailUser PrimarySMTPAddress is part of target accepted domains" -ForegroundColor Green
}

#EMailAddresses
Write-Verbose -Message "Informational: Checking for EmailAddresses on TARGET object that are not on the TARGET accepted domains list"
foreach ($Address in $TargetObject.EmailAddresses) {
if ($Address.StartsWith("SMTP:") -or $Address.StartsWith("smtp:")) {
if ($TargetTenantAcceptedDomains.DomainName -notcontains $Address.Split("@")[1]) {
if ($TargetTenantAcceptedDomains.DomainName -contains $Address.Split("@")[1]) {
Write-Host ">> EmailAddress $($Address) is part of the target accepted domains" -ForegroundColor Green
} else {
if (!$TargetObject.IsDirSynced) {
Write-Host ">> Error: $($Address) is not part of your organization, would you like to remove it? (Y/N): " -ForegroundColor Red -NoNewline
$RemoveAddressOption = Read-Host
Expand All @@ -401,8 +404,6 @@ function CheckObjects {
Write-Host ">> Error: $($Address) is not part of your organization. The object is DirSynced and this is not a change that can be done directly on EXO. Please do remove the address from on-premises and perform an AADConnect delta sync" -ForegroundColor Red
}
}
} else {
Write-Host ">> Target MailUser ProxyAddresses are all part of the target organization" -ForegroundColor Green
}
}

Expand All @@ -411,7 +412,9 @@ function CheckObjects {
if ($SourceObject.EmailAddresses -like '*500:*') {
Write-Verbose -Message "SOURCE mailbox contains X500 addresses, checking if they're present on the TARGET MailUser"
foreach ($Address in ($SourceObject.EmailAddresses | Where-Object { $_ -like '*500:*' })) {
if ($TargetObject.EmailAddresses -notcontains $Address) {
if ($TargetObject.EmailAddresses -contains $Address) {
Write-Verbose -Message "Informational: The X500 address $($Address) from SOURCE object is present on TARGET object"
} else {
if (!$TargetObject.IsDirSynced) {
Write-Host ">> Error: $($Address) is not present on the TARGET MailUser, would you like to add it? (Y/N): " -ForegroundColor Red -NoNewline
$AddX500 = Read-Host
Expand All @@ -425,8 +428,6 @@ function CheckObjects {
} else {
Write-Host ">> Error: $($Address) is not present on the TARGET MailUser and the object is DirSynced. This is not a change that can be done directly on EXO, please add the X500 address from on-premises and perform an AADConnect delta sync" -ForegroundColor Red
}
} else {
Write-Host ">> Informational: The X500 address from SOURCE object is present on TARGET object" -ForegroundColor Green
}
}
} else {
Expand Down Expand Up @@ -651,9 +652,12 @@ function CheckObjectsSourceOffline {

#PrimarySMTP
Write-Verbose -Message "Informational: Checking if the PrimarySTMPAddress of TARGET belongs to a TARGET accepted domain"
if ($TargetTenantAcceptedDomains.DomainName -notcontains $TargetObject.PrimarySmtpAddress.Split('@')[1]) {
if ($TargetTenantAcceptedDomains.DomainName -contains $TargetObject.PrimarySmtpAddress.Split('@')[1]) {
Write-Host ">> Target MailUser PrimarySMTPAddress is part of target accepted domains" -ForegroundColor Green
} else {
Write-Host ">> Error: The Primary SMTP address $($TargetObject.PrimarySmtpAddress) of the MailUser does not belong to an accepted domain on the target tenant" -ForegroundColor Red -NoNewline
if (!$TargetObject.IsDirSynced) {
Write-Host ">> Error: The Primary SMTP address $($TargetObject.PrimarySmtpAddress) of the MailUser does not belong to an accepted domain on the target tenant, would you like to set it to $($TargetObject.UserPrincipalName) (Y/N): " -ForegroundColor Red -NoNewline
Write-Host ">> would you like to set it to $($TargetObject.UserPrincipalName) (Y/N): " -ForegroundColor Red -NoNewline
$PrimarySMTPAddressSetOption = Read-Host
Write-Host " Your input: $($PrimarySMTPAddressSetOption)"
if ($PrimarySMTPAddressSetOption.ToLower() -eq "y") {
Expand All @@ -663,17 +667,17 @@ function CheckObjectsSourceOffline {
$TargetObject = Get-TargetMailUser $TargetIdentity
}
} else {
Write-Host ">> Error: The Primary SMTP address $($TargetObject.PrimarySmtpAddress) of the MailUser does not belong to an accepted domain on the target tenant. The object is DirSynced and this is not a change that can be done directly on EXO, please do the change on-premises and perform an AADConnect delta sync" -ForegroundColor Red
Write-Host ">> Error: The Primary SMTP address $($TargetObject.PrimarySmtpAddress) of the MailUser does not belong to an accepted domain on the target tenant. The object is DirSynced and this is not a change that can be done directly on EXO. Please do the change on-premises and perform an AADConnect delta sync" -ForegroundColor Red
}
} else {
Write-Host ">> Target MailUser PrimarySMTPAddress is part of target accepted domains" -ForegroundColor Green
}

#EMailAddresses
Write-Verbose -Message "Informational: Checking for EmailAddresses on TARGET object that are not on the TARGET accepted domains list"
foreach ($Address in $TargetObject.EmailAddresses) {
if ($Address.StartsWith("SMTP:") -or $Address.StartsWith("smtp:")) {
if ($TargetTenantAcceptedDomains.DomainName -notcontains $Address.Split("@")[1]) {
if ($TargetTenantAcceptedDomains.DomainName -contains $Address.Split("@")[1]) {
Write-Host ">> EmailAddress $($Address) is part of the target accepted domains" -ForegroundColor Green
} else {
if (!$TargetObject.IsDirSynced) {
Write-Host ">> Error: $($Address) is not part of your organization, would you like to remove it? (Y/N): " -ForegroundColor Red -NoNewline
$RemoveAddressOption = Read-Host
Expand All @@ -685,11 +689,9 @@ function CheckObjectsSourceOffline {
$TargetObject = Get-TargetMailUser $TargetIdentity
}
} else {
Write-Host ">> Error: $($Address) is not part of your organization. The object is DirSynced and this is not a change that can be done directly on EXO, please remove the address from on-premises and perform an AADConnect delta sync" -ForegroundColor Red
Write-Host ">> Error: $($Address) is not part of your organization. The object is DirSynced and this is not a change that can be done directly on EXO. Please do remove the address from on-premises and perform an AADConnect delta sync" -ForegroundColor Red
}
}
} else {
Write-Host ">> Target MailUser ProxyAddresses are all part of the target organization" -ForegroundColor Green
}
}

Expand All @@ -698,7 +700,9 @@ function CheckObjectsSourceOffline {
if ($SourceObject.EmailAddresses -like '*500:*') {
Write-Verbose -Message "SOURCE mailbox contains X500 addresses, checking if they're present on the TARGET MailUser"
foreach ($Address in ($SourceObject.EmailAddresses | Where-Object { $_ -like '*500:*' })) {
if ($TargetObject.EmailAddresses -notcontains $Address) {
if ($TargetObject.EmailAddresses -contains $Address) {
Write-Verbose -Message "Informational: The X500 address $($Address) from SOURCE object is present on TARGET object"
} else {
if (!$TargetObject.IsDirSynced) {
Write-Host ">> Error: $($Address) is not present on the TARGET MailUser, would you like to add it? (Y/N): " -ForegroundColor Red -NoNewline
$AddX500 = Read-Host
Expand All @@ -710,10 +714,8 @@ function CheckObjectsSourceOffline {
$TargetObject = Get-TargetMailUser $TargetIdentity
}
} else {
Write-Host ">> Error: $($Address) is not present on the TARGET MailUser. The object is DirSynced and this is not a change that can be done directly on EXO, please add the address on-premises and perform an AADConnect delta sync" -ForegroundColor Red
Write-Host ">> Error: $($Address) is not present on the TARGET MailUser and the object is DirSynced. This is not a change that can be done directly on EXO, please add the X500 address from on-premises and perform an AADConnect delta sync" -ForegroundColor Red
}
} else {
Write-Host ">> Informational: The X500 address from SOURCE object is present on TARGET object" -ForegroundColor Green
}
}
} else {
Expand Down
Loading

0 comments on commit 238eacb

Please sign in to comment.