Connect-Mailbox and AllowLagacyDNMismatch

I have solved a one case where we wanted to connect (Use the Connect-Mailbox cmdlet to connect a disconnected mailbox to an Active Directory user object.) an archive mailbox to a linked mailbox in Exchange 2013.

Error from EMS:

25- 7- 2014 10-32-07

[PS] C:\>Connect-Mailbox -Identity "Personal Archive - Jan Novak" -Archive -User JanNovak2 -Database "EXDAG1-DB03"
WARNING: An unexpected error has occurred and a Watson dump is being generated: Object reference not set to an instance
 of an object.
Object reference not set to an instance of an object.
    + CategoryInfo          : NotSpecified: (:) [Connect-Mailbox], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.Exchange.Management.MapiTasks.ConnectMailbox
    + PSComputerName        :

Error from GUI:

The LegacyDN "/o=CONTOSO/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Jan Novak" of "cb67270a-ada2-472e-94cc-eb7140f3520f" is in use by the following user in Active Directory: "Pepa Novak (new)". The value for LegacyDN must be unique to each user.

Obviously, the LegacyDN attribute was not unique and defended to connect the mailbox.

[PS] C:\> # disconnected archive
[PS] C:\>(Get-mailboxdatabase|Get-Mailboxstatistics|?{$_.DisconnectReason -ne $null -and $_.DisplayName -like "*Jan*"}).LegacyDN
/o=CONTOSO /ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Jan Novak

[PS] C:\># linked mailbox
[PS] C:\>(Get-mailbox JanNovak2).LegacyDN
/o=contoso/ou=exchange administrative group (fydibohf23spdlt)/cn=recipients/cn=Jan Novak

How to connect mailbox in case this case? According to Technet and Connect-Mailbox (Exchange 2013) there is available a switch:

25- 7- 2014 10-23-48Well, we have available the switch for similar scenario (i.e. AllowLagacyDNMismatch), but it is reserved only for MS use. I do not know why is it so (let me know if you a clue), but it worked for me without problem:

[PS] C:\> Connect-Mailbox -Identity "Personal Archive - Jan Novak" -Archive -User JanNovak2 -Database "EXDAG1-DB03" -AllowLegacyDNMismatch

[PS] C:\> Test-ArchiveConnectivity

RunspaceId               : 7df20326-4fc0-4ca3-877f-5273aea0d5b7
Identity                 :
PrimaryMRMConfiguration  :
PrimaryLastProcessedTime :
ArchiveDomain            :
ArchiveDatabase          : EXDAG1-DB03
ArchiveMRMConfiguration  :
ArchiveLastProcessedTime :
ComplianceConfiguration  : ElcV2
ItemMRMProperties        :
Result                   : Successfully logged on to the users Archive mailbox.
Error                    :
IsValid                  : True
ObjectState              : New


Let me publish my script which tests and gathers information directly from Exchange server 2010 (Windows 2008). It is my little helper in case of patching or troubleshooting. Basically it is nothing special, but let’s look at its help:

    Test-ExchangeServer2010.ps1 - - v1.180714
    This script performs test cmdlets and gathers information from Exchange Server 2010 (Windows Server 2008) into own txt log.
    It can be used only directly on the Exchanger server (the server role is chosen automatically). 
    Only get and test cmdlets are used for this type of health check.
    Run-space: PowerShell 2.0 or Exchange Management Shell.
    Prerequisite: new-TestCasConnectivityUser.ps1
    Tests and information:
        - Get-WMIObject (Operating System, Volumes)
        - Get-ExchangeServer
        - GCM Exsetup
        - Test-ServiceHealth
        - Get-ExchangeCertificate
        - IIS Status
        - Test-PowerShellConnectivity
        - Test-FederationTrust
        - Server Services
        - Bad Application Events
        - Bad System Evenets
        - Top processes - CPU,MemorySize
        - Server Performance
      Mailbox role:
        - Get-MailboxDatabaseCopyStatus
        - Get-DatabaseAvailabilityGroup
        - Cluster /quorum
        - Cluster group /stat
        - Cluster /prop
        - Test-Mailflow
        - Test-MAPIConnectivity
        - Test-ReplicationHealth
      CAS role:
        - Test-OwaConnectivity
        - Test-ActiveSyncConnectivity
        - Test-WebServicesConnectivity
        - Test-OutlookWebServices
        - Test-OutlookWebServices
        - Test-OutlookConnectivity
        - Test-EcpConnectivity
        - Test-ImapConnectivity
        - Test-PopConnectivity
      HUB role:
        - Test-SmtpConnectivity
        - Get-Queue
    # It performs test cmdlets and gathers information into txt log generated in C:\temp.
    Test-ExchangeServer.ps1 -ShowOutputLog
    # It performs test cmdlets and gathers information into txt log generated in C:\temp and opens the log in notepad at the end.
    Test-ExchangeServer.ps1 -OutputLogPath "D:\Report\ExchangeServerLog.txt"
    # It performs test cmdlets and gathers information into the specified log file.
    Test-ExchangeServer.ps1 -ShowOutputLog -OutputLogPath "D:\Report\ExchangeServerLog.txt"
    # It performs test cmdlets and gathers information into the specified log file and opens the log in notepad at the end.

How to use it?

Just copy the script to your Exchange server and go ahead:

19- 7- 2014 13-07-58Output log as its result:

19- 7- 2014 13-17-56How to compare logs (i.e. check the state before/after patching)?

For example via Total Commander:

19- 7- 2014 12-50-56Download: Test-ExchangeServer2010.ps1 –


Exchange disk statistics

Here is a tip how to gather disk statistics such as
CapacityGB, FreeSpaceGB, FreeSpace% for all disks in your Exchange organization.

$vols = @()
Get-ExchangeServer | % { 
$comp = $_.Name
$vols += Get-WmiObject -computername $comp -query "select Name, DriveType, FileSystem, FreeSpace,   Capacity, Label from Win32_Volume where DriveType = 2 or DriveType = 3" | select @{Name='Server';Expression={$comp}},Label,Name,@{Name='CapacityGB';Expression={$_.Capacity/1GB}},@{Name='FreeSpaceGB';Expression={$_.FreeSpace/1GB}},@{Name='FreeSpace%';Expression={($_.FreeSpace*100)/$_.Capacity}}
$vols | Export-Csv -NoTypeInformation -Delimiter ";" -path "E:\ExchangeDiskreport.csv"


Exchange Error: The handshake failed due to an unexpected packet format

A customer reported inoperative IMAP functionality for some user mailboxes. I checked all CAS servers and discovered the following issue with one of them:

[PS] C:\>Test-ImapConnectivity -ClientAccessServer ServerEx10a|fl

RunspaceId                  : ad18027f-3e0f-44c2-a192-ff24b54e0680
LocalSite                   : Contoso-office
SecureAccess                : False
VirtualDirectoryName        :
Url                         :
UrlType                     : Unknown
Port                        : 993
ConnectionType              : Ssl
ClientAccessServerShortName : ServerEx10a
LocalSiteShortName          : Contoso-office
ClientAccessServer          :
Scenario                    : Test IMAP4 Connectivity
ScenarioDescription         : Connect to server using IMAP4 protocol, search for the test message, and delete it along
                              with any messages that are older than 24 hours.
PerformanceCounterName      : ImapConnectivity-Latency
Result                      : Failure
Error                       : Microsoft.Exchange.Monitoring.ProtocolException: Authentication failed. The connection is
                               being closed.
                              The handshake failed due to an unexpected packet format.Server response while making conn
                              ection:[]. ---> System.IO.IOException: The handshake failed due to an unexpected packet f
UserName                    : extest_f865f9d53e494
StartTime                   : 2/13/2014 9:11:03 AM
Latency                     : 00:00:00.0144858
EventType                   : Error
LatencyInMillisecondsString :
Identity                    :
IsValid                     : True

Error “Microsoft.Exchange.Monitoring.ProtocolException: Authentication failed. The connection is being closed. The handshake failed due to an unexpected packet format. Server response while making connection:[]. —> System.IO.IOException: The handshake failed due to an unexpected packet format.” was due to the missing intermediate certification authority (CA) certificate. I unified the cert (export/import) among CAS servers to get it fixed.

4- 3- 2014 21-07-41Exchange 2010 – Understanding POP3 and IMAP4

Exchange Error: Exception has been thrown by the target of an invocation

Microsoft Exchange error “Exception has been thrown by the target of an invocation” indicates issues for background process to modify the settings of existing mailbox object.4- 3- 2014 20-31-20In my case, I could not enable an email address policy for a user mailbox. It was caused by wrong declaration of %rxy and replacing subsequent characters in the policy (missing r character).

Exchange 2013 – Email Address Policies

KB822447 – How to Modify an SMTP E-Mail Address by Using Recipient Policies

Exchange Tip: Double quotation marks

MS support requested to modify the time limit of a cross-forest AutoDiscover operation via the RecipientResolutionTimeoutInSeconds property (KB928812). Just adding the following line into Web.config was needed:

1- 3- 2014 12-27-28The line added and the availability service destroyed (affected OoO, free/busy, Autodiscover).

It was caused by an invalid form of double quotation marks (despite copy/paste through notepad).

Bear in mind to update config files carefully and double check related syntax. Use only supported double quotation marks " and omit  ” ‟ “ ″ .

Exchange Tip: Exchange Data Type – ByteQuantifiedSize

Here are few tips how to work with ByteQuantifiedSize (Microsoft.Exchange.Data.ByteQuantifiedSize – Microsoft.Exchange.Data.dll) that is typical for Exchange sizes such as TotalDeletedItemSize, FolderSize, TotalItemSize, RecoverableItemsQuota, AvailableNewMailboxSpace etc.

# Example for BQS property
[PS] C:\> Get-MailboxStatistics filip |select TotalItemSize

4.38 MB (4,592,642 bytes)

# Get BQS value
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.Value

4.38 MB (4,592,642 bytes)

# Check BQS methods especially ToBytes, ToKB, ToMB, ToGB, ToTB
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.value|Get-Member

TypeName: Microsoft.Exchange.Data.ByteQuantifiedSize

Name          MemberType Definition
----          ---------- ----------
CompareTo     Method     int CompareTo(Microsoft.Exchange.Data.ByteQuantifiedSize other)
Equals        Method     bool Equals(System.Object obj), bool Equals(Microsoft.Exchange.Data.ByteQuantifiedSize other)
GetHashCode   Method     int GetHashCode()
GetType       Method     type GetType()
RoundUpToUnit Method     System.UInt64 RoundUpToUnit(Microsoft.Exchange.Data.ByteQuantifiedSize+Quantifier quantifier)
ToBytes       Method     System.UInt64 ToBytes()
ToGB          Method     System.UInt64 ToGB()
ToKB          Method     System.UInt64 ToKB()
ToMB          Method     System.UInt64 ToMB()
ToString      Method     string ToString(), string ToString(string format), string ToString(string format, System.IF...
ToTB          Method     System.UInt64 ToTB()

# Get BQS value (4.38 MB) in bytes
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.Value.toBytes()


# Get BQS values in bytes from more objects
[PS] C:\> Get-Mailbox -Anr "fil"|Get-MailboxStatistics |%{$_.TotalItemSize.Value.toBytes()}


# Be careful to use BQS methods like ToGB because output is UInt64 (4.38 MB in GB?)
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.Value.toGB()


# Get BQS as Double
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.Value.toBytes()/1GB


# Select BQS value as needed
[PS] C:\> Get-MailboxStatistics filip|select @{Name='TotalItemSizeBytes';Expression={$_.TotalItemSize.Value.toBytes()/1GB}}


# BQS value as string
[PS] C:\> $string=(Get-MailboxStatistics filip).TotalItemSize.Value.toString()    
[PS] C:\> $string="4.38 MB (4,592,642 bytes)"

# Get bytes from BQS string
[PS] C:\> $string|%{($_.Substring($_.indexof("(")+1,$_.indexof("b")-$_.indexof("(")-2)) -replace(",","")}


# Get BQS string in GB
[PS] C:\> ($string|%{($_.Substring($_.indexof("(")+1,$_.indexof("b")-$_.indexof("(")-2)) -replace(",","")})/1GB

# Parse BQS string
[PS] C:\> [Microsoft.Exchange.Data.ByteQuantifiedSize]::Parse("$string")

4.38 MB (4,592,642 bytes)

[PS] C:\> ([Microsoft.Exchange.Data.ByteQuantifiedSize]::Parse("$string")).gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     ByteQuantifiedSize                       System.ValueType

# Invalid measuring for BQS values - ERROR
[PS] C:\> Get-Mailbox -Anr "fil"|Get-MailboxStatistics| Measure-Object -Sum -Average -Maximum -Minimum -Property TotalItemSize

Measure-Object : Input object "14.79 MB (15,511,742 bytes)" is not numeric.
At line:1 char:62
+ Get-Mailbox -Anr "fil"|Get-MailboxStatistics| Measure-Object <<<<  -Sum -Average -Maximum -Minimum -Property TotalItemSize
+ CategoryInfo          : InvalidType: (14.79 MB (15,511,742 bytes):Unlimited`1) [Measure-Object], PSInvalidOperat   ionException
+ FullyQualifiedErrorId : NonNumericInputObject,Microsoft.PowerShell.Commands.MeasureObjectCommand

# Measure BQS values
[PS] C:\> Get-Mailbox -Anr "fil"|Get-MailboxStatistics|%{$_.TotalItemSize.Value.toBytes()}| Measure-Object -Sum -Average -Maximum -Minimum

Count    : 4
Average  : 401522533
Sum      : 1606090132
Maximum  : 986385403
Minimum  : 13339213
Property :

# Measure BQS values as needed
[PS] C:\>Get-Mailbox -Anr "koch"|Get-MailboxStatistics|%{$_.TotalItemSize.Value.toBytes()}| Measure-Object -Sum |select@{Name='TotalMailboxSizeGB';Expression={$_.sum/1GB}}