microsoft / microsoft/CSS-Exchange
Adopt shared Connect-EXOAdvanced in PublicFolders/MailPublicFolderSync/* scripts
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 1.3k
- Forks
- 395
- Avg merge
- 14h 7m
- Merged PRs (30d)
- 5
Description
Parent: #2590
Depends on: #2591
Refactor the five root scripts in PublicFolders/MailPublicFolderSync/ to use the shared Connect-EXOAdvanced / Disconnect-EXOAdvanced helper. All five carry the same silent-failure pattern documented in the parent issue.
Scripts
-
PublicFolders/MailPublicFolderSync/Sync-ModernMailPublicFolders.ps1— remove the connect block PR #2589 just added and call the helper instead. Preserves sovereign-cloud support. -
PublicFolders/MailPublicFolderSync/Sync-MailPublicFolders.ps1 -
PublicFolders/MailPublicFolderSync/Sync-MailPublicFoldersCloudToOnprem.ps1 -
PublicFolders/MailPublicFolderSync/Import-MailPublicFolders.ps1— also fix unguardedDisconnect-ExchangeOnlineat line 244 and line 257 — replace withDisconnect-EXOAdvanced -Connection $exoso we only tear down what we opened. -
PublicFolders/MailPublicFolderSync/Import-PublicFolderMailboxes.ps1
Problem code (representative)
Sync-MailPublicFolders.ps1#L169-L193:
try {
Import-Module ExchangeOnlineManagement -ErrorAction SilentlyContinue
if (Get-Module ExchangeOnlineManagement) {
$connectParams = @{
ConnectionUri = $ConnectionUri
Prefix = "Remote"
ErrorAction = "SilentlyContinue" # 🐛 silent auth failure
}
if ($null -ne $Credential) { $connectParams.Credential = $Credential }
Connect-ExchangeOnline @connectParams
$script:isConnectedToExchangeOnline = $true # 🐛 set even if Connect failed
} else {
Write-Warning $LocalizedStrings.EXOV2ModuleNotInstalled
exit
}
} finally { ... }
Target pseudocode
. $PSScriptRoot\..\..\Shared\M365\EXOConnection.ps1
$exo = Connect-EXOAdvanced -ConnectionUri $ConnectionUri `
-AzureADAuthorizationEndpointUri $AzureADAuthorizationEndpointUri `
-Credential $Credential `
-Prefix 'Remote'
if (-not $exo) { return } # helper printed the reason
try {
# ...existing sync logic...
} finally {
Disconnect-EXOAdvanced -Connection $exo # only disconnects the session we opened
}
Removes:
- The
InitializeExchangeOnlineRemoteSessionfunction - The
$script:isConnectedToExchangeOnlinestate variable - The
Disconnect-ExchangeOnlinecleanup block - The
EXOV2ModuleNotInstalledlocalized string (owned by the helper now)
Validation
- Existing Pester tests for
Sync-ModernMailPublicFolders.ps1must be updated to mockConnect-EXOAdvanced/Disconnect-EXOAdvancedinstead ofConnect-ExchangeOnline/Import-Module. - New Pester tests for the other four scripts covering: connect success, connect failure returns early, disconnect only called when connect succeeded.
- Lab test: minimum one full sync run in a real tenant and one in a sovereign-cloud tenant.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Shared/M365/EXOConnection.ps1 and the five scripts under PublicFolders/MailPublicFolderSync/, comparing their current connection and cleanup blocks with the target helper usage. Update the existing Sync-ModernMailPublicFolders.ps1 Pester tests and add coverage for the other four scripts for connection success, early return on failure, and conditional disconnect; done includes the requested full-sync lab checks in standard and sovereign-cloud tenants.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- cloud, tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100