-
Notifications
You must be signed in to change notification settings - Fork 0
Clear OnPremExchangeAttributes
Removes on-premises Exchange attributes from Active Directory user accounts to enable cloud mailbox provisioning in Exchange Online. This script is essential when decommissioning on-premises Exchange or migrating to a cloud-only Exchange Online environment without hybrid configuration.
- Pre-execution backup of all Exchange attributes to CSV with base64 encoding for binary data
- Comprehensive attribute removal including msExchMailboxGuid (primary blocker) and 18+ other Exchange attributes
-
Rollback capability using backup data with
-RestoreFromBackupparameter - Flexible targeting - single user, OU-based, or CSV bulk import
- WhatIf support for safe testing before execution
- Detailed logging with timestamped status messages and color-coded output
- Automatic validation checks before and after cleanup
- Summary reports with execution statistics and next steps
- Active Directory PowerShell module (RSAT tools)
- Domain Administrator or Account Operator permissions
- PowerShell 5.1 or later
- Network connectivity to Active Directory domain controllers
- Identity: The SamAccountName, UserPrincipalName, or DistinguishedName of a single user to process
- SearchBase: Active Directory OU to search for users (e.g., "OU=Users,OU=ToMigrate,DC=contoso,DC=com")
- InputFile: Path to CSV file with users (must contain 'Identity' column)
-
OutputDirectory: Directory for backups and reports (Default:
C:\Reports\ExchangeCleanup) - AttributesToRemove: Specific Exchange attributes to remove (defaults to standard blocking attributes)
- BackupOnly: Only creates backup without removing attributes (useful for assessment)
- RestoreFromBackup: Path to backup CSV file for rollback operations
- WhatIf: Shows what would happen without making changes
- Force: Bypasses confirmation prompts (use with caution)
- ListAttributes: Lists all Exchange-related attributes and exits
.\Clear-OnPremExchangeAttributes.ps1 -Identity "jsmith" -WhatIfTests removal of Exchange attributes without making changes. Review the attributes that would be removed.
.\Clear-OnPremExchangeAttributes.ps1 -Identity "jsmith"Backs up and removes Exchange attributes for user jsmith. Requires typing PROCEED to confirm.
.\Clear-OnPremExchangeAttributes.ps1 -Identity "jsmith" -BackupOnlyCreates backup of Exchange attributes without removing them. Useful for auditing what attributes exist.
# Create CSV with user identities
$users = @('jsmith', 'mjones', 'bwilson')
$users | ForEach-Object { [PSCustomObject]@{Identity=$_} } | Export-Csv "C:\temp\users.csv" -NoTypeInformation
# Process all users
.\Clear-OnPremExchangeAttributes.ps1 -InputFile "C:\temp\users.csv"Processes multiple users from CSV file. Type PROCEED when prompted to execute.
.\Clear-OnPremExchangeAttributes.ps1 -SearchBase "OU=ToMigrate,OU=Users,DC=contoso,DC=com"Backs up and removes Exchange attributes for all users in specified OU.
.\Clear-OnPremExchangeAttributes.ps1 -Identity "jsmith" -ForceBypasses confirmation prompt. Use with caution in production.
.\Clear-OnPremExchangeAttributes.ps1 -RestoreFromBackup "C:\Reports\ExchangeCleanup\ExchangeAttributes_Backup_20260202_143052.csv"Restores Exchange attributes from previous backup. Requires typing RESTORE to confirm.
.\Clear-OnPremExchangeAttributes.ps1 -ListAttributesDisplays all Exchange attributes that can be removed (default and extended lists).
The script provides real-time color-coded status messages:
- Cyan - Informational messages and headers
- Green - Success messages with β checkmark
-
Yellow - Warnings with
β οΈ symbol - Red - Errors with β symbol
Default output directory: C:\Reports\ExchangeCleanup\
Generated files follow timestamp pattern: {Type}_{YYYYMMDD_HHmmss}.{ext}
Pattern: ExchangeAttributes_Backup_YYYYMMDD_HHmmss.csv
Example: ExchangeAttributes_Backup_20260202_143052.csv
Contains complete backup of all Exchange attributes for processed users including:
- Standard user properties (SamAccountName, UPN, DN, DisplayName, Enabled)
- All Exchange attributes (msExchMailboxGuid, legacyExchangeDN, mailNickname, etc.)
- Binary data encoded in base64 format
- Backup timestamp
Pattern: ExchangeCleanup_Results_YYYYMMDD_HHmmss.csv
Example: ExchangeCleanup_Results_20260202_143052.csv
Contains detailed results for each user:
-
User: SamAccountName -
RemovedCount: Number of attributes successfully removed -
RemovedAttributes: List of removed attribute names -
FailedAttributes: List of attributes that failed to remove -
SkippedAttributes: Attributes with no values -
Success: Boolean indicating if operation succeeded
Pattern: ExchangeCleanup_Summary_YYYYMMDD_HHmmss.txt
Example: ExchangeCleanup_Summary_20260202_143052.txt
Comprehensive summary including:
- Operation statistics (total processed, successful, errors, skipped)
- File locations for backup and results
- Execution time and duration
- Error details if any occurred
- Next steps for completing migration
These attributes prevent cloud mailbox provisioning:
- msExchMailboxGuid - Primary blocker, must be removed
- msExchArchiveGUID - Archive mailbox identifier
- msExchRemoteRecipientType - Remote recipient type flags
- msExchRecipientDisplayType - Display type (1073741824 = user mailbox)
- msExchRecipientTypeDetails - Detailed recipient type
- msExchUserCulture - User locale settings
- msExchVersion - Exchange schema version
- msExchMailboxSecurityDescriptor - Mailbox permissions
- msExchMasterAccountSid - Master account SID
- msExchPoliciesExcluded - Policy exclusions
- msExchRecipientSoftDeletedStatus - Soft delete status
- msExchUserAccountControl - Account control flags
- msExchWhenMailboxCreated - Mailbox creation timestamp
- mailNickname - Exchange alias
- legacyExchangeDN - Legacy distinguished name
- targetAddress - Routing address
- msExchHomeServerName - Home server path
- homeMDB - Mailbox database location
- msExchMailboxTemplateLink - Mailbox template reference
Additional attributes removed with -AttributesToRemove parameter:
- msExchAddressBookFlags, msExchArchiveDatabaseLink, msExchArchiveName
- msExchArchiveQuota, msExchArchiveWarnQuota, msExchBypassAudit
- msExchBypassModerationLink, msExchDelegateListLink, msExchELCMailboxFlags
- msExchHideFromAddressLists, msExchMailboxAuditEnable, msExchMailboxFolderSet
- msExchMobileMailboxFlags, msExchProvisioningFlags, msExchRBACPolicyLink
- msExchRecipientLimit, msExchRetentionComment, msExchRetentionURL
- msExchSafeSendersHash, msExchTextMessagingState, msExchUMDtmfMap
Solution: Install RSAT tools:
# Windows 10/11
Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0
# Windows Server
Install-WindowsFeature RSAT-AD-PowerShellSolution:
- Ensure you're running from domain-joined machine
- Verify network connectivity to domain controller
- Check if you have appropriate permissions
Solution:
# Run with different output directory
.\Clear-OnPremExchangeAttributes.ps1 -Identity "jsmith" -OutputDirectory "C:\temp\ExchangeCleanup"Solution:
- Verify user exists in Active Directory
- Check spelling of username
- Try using UserPrincipalName or DistinguishedName instead
Cause: Attributes may not have values or were already removed
Solution: Check backup CSV to see if attributes existed:
Import-Csv "C:\Reports\ExchangeCleanup\ExchangeAttributes_Backup_*.csv" |
Select-Object SamAccountName, msExchMailboxGuid, mailNickname, legacyExchangeDN |
Format-ListPossible Causes:
- Azure AD Connect hasn't synced changes yet
- User still has mailbox license assigned before attributes were cleared
- Deleted mailbox still in soft-deleted state in Exchange Online
Solution:
# 1. Force Azure AD Connect sync
Start-ADSyncSyncCycle -PolicyType Delta
# 2. Wait 15-30 minutes, then remove and reassign license
# 3. Check for soft-deleted mailboxes in Exchange Online
Connect-ExchangeOnline
Get-Mailbox -SoftDeletedMailbox -Identity "user@domain.com"If mailbox provisioning fails or you need to restore original state:
# Restore from backup
.\Clear-OnPremExchangeAttributes.ps1 -RestoreFromBackup "C:\Reports\ExchangeCleanup\ExchangeAttributes_Backup_20260202_143052.csv"
# Type: RESTORE
# Wait for completion
# Force Azure AD Connect sync
Start-ADSyncSyncCycle -PolicyType Delta# Check what was removed
Import-Csv "C:\Reports\ExchangeCleanup\ExchangeCleanup_Results_*.csv" |
Where-Object { $_.RemovedCount -gt 0 } |
Format-Table User, RemovedCount, Success -AutoSize# On Azure AD Connect server
Start-ADSyncSyncCycle -PolicyType DeltaAllow 15-30 minutes for changes to replicate to Azure AD.
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Assign license (example)
Set-MgUserLicense -UserId "jsmith@contoso.com" -AddLicenses @{SkuId="<License-SKU-ID>"} -RemoveLicenses @()Connect-ExchangeOnline
# Check if mailbox exists
Get-Mailbox -Identity "jsmith@contoso.com"
# May take 30-60 minutes for mailbox to provisionSend test email to verify mailbox is functioning correctly.
- Decommissioning on-premises Exchange after full migration to Exchange Online
- Moving to Exchange Online without hybrid configuration
- Fixing orphaned Exchange attributes from previous failed migrations
- Preparing users for cloud-only mailboxes after data migration
- Resolving "mailbox already exists" errors in Exchange Online
- Active hybrid Exchange environments - use proper migration tools instead
- Users with active on-premises mailboxes - migrate data first
- Environments with Exchange Online Hybrid - use New-MoveRequest
- Production without testing - always test with -WhatIf first
- Always backup before running (script does this automatically)
- Test with
-WhatIffirst - Verify backup file was created successfully
- This disconnects users from on-premises Exchange mailboxes
- Ensure all mailbox data has been migrated to Exchange Online
- Verify users have appropriate Exchange Online licenses
- Confirm Azure AD Connect is functioning properly (if hybrid)
- Once attributes are cleared, on-premises mailbox link is permanently broken
- Use
-RestoreFromBackupto rollback if needed - Keep backup files in secure location
- Get-ComprehensiveADReport.ps1 - Assess AD environment before migration
- Get-MailboxPermissionsReport.ps1 - Document mailbox permissions
- New-Office365Accounts.ps1 - Create Exchange Online mailboxes
-
v1.0 (2026-02-02): Initial release
- Core functionality for removing Exchange attributes
- Backup and restore capabilities
- Support for single user, OU, and bulk CSV processing
- WhatIf support and comprehensive error handling
- Improved attribute detection for accurate removal
- Overview
- Start-LyncCsvExporter
- Get-ComprehensiveLyncReport
- Get-LyncHealthReport
- Get-LyncInfrastructureReport
- Get-LyncServiceStatus
- Get-LyncUserRegistrationReport
- Export-ADLyncTeamsMigrationData
- New-Office365Accounts
- Sync-ContactsFromCsv
- Set-EmailToSharedAccount
- Set-SMTPForward
- Invoke-UserSignOutAndBlock
- Security Assessment Scripts (coming soon)
- Azure Automation (documentation pending)
- Get-GraphToken
- Get-GraphHeaders
- Get-AzureResourcePaging
- Get-EnterpriseAppUsage
- Get-ExchangeErrorsGraph
- Get-PBIWorkspaceUsageReport
- Intune Management (documentation pending)