<# .SYNOPSIS Convert-MailboxToMailuser will convert an existing mailbox to a mailuser .DESCRIPTION Convert-MailboxToMailuser will convert an existing mailbox to a mailuser. It will copy the main Exchange properties from the mailbox to the mailuser .PARAMETER Identity The Identity parameter specifies the identity of the mailbox. You can use one of the following values: * GUID * Distinguished name (DN) * Display name * Domain\Account * User principal name (UPN) * LegacyExchangeDN * SmtpAddress * Alias .PARAMETER DomainController The DomainController parameter specifies the fully qualified domain name (FQDN) of the domain controller that retrieves data from Active Directory. .Parameter ExternalEmailAddress The ExternalEmailAddress parameter specifies an e-mail address outside the organization. E-mail messages sent to the user are sent to this external address. .EXAMPLE This example converts the mailbox Chris to a mailuser with the external email address Chris@contoso.com .\Convert-MailboxToMailUser.ps1 -Identity Chris -ExternalEmailAddress Chris@contoso.com .EXAMPLE This example converts the mailbox Chris to a mailuser with the external email address Chris@contoso.com using the specified domain controller .\Convert-MailboxToMailUser.ps1 -Identity Chris -ExternalEmailAddress Chris@contoso.com -DomainController MyDC #> [CmdletBinding( SupportsShouldProcess=$true, ConfirmImpact="High" )] Param ( [Parameter(Mandatory=$true,Position=0)] [String]$Identity, [Parameter(Mandatory=$true,Position=1)] [String]$ExternalEmailAddress, [Parameter(Mandatory=$false,Position=2)] [String]$DomainController ) PROCESS { $parameters = @{} if( $DomainController ) { $parameters.Add( 'DomainController', $DomainController ) Write-Verbose ( 'Using Domain Controller "{0}"' -f $DomainController ) } Write-Verbose ( 'Trying to find mailbox for "{0}"' -f $Identity ) $OldMailbox = get-mailbox $Identity @parameters -ErrorAction SilentlyContinue if( ($OldMailbox) -and -not ($OldMailbox.count -gt 1) ) { if( $pscmdlet.ShouldProcess($OldMailbox.DistinguishedName) ) { $parameters.add( 'Identity', $OldMailbox.DistinguishedName ) Write-Verbose ( 'Disabling mailbox "{0}"' -f $OldMailbox.DistinguishedName ) disable-mailbox @parameters -confirm:$false $parameters.add( 'ExternalEmailAddress', $ExternalEmailAddress ) Write-Verbose ( 'Enabling mailuser "{0}"' -f $OldMailbox.DistinguishedName ) enable-mailuser @parameters $parameters.add( 'EmailAddressPolicyEnabled', $OldMailbox.EmailAddressPolicyEnabled ) $EmailAddresses= @( 'x500:{0}' -f $OldMailbox.legacyExchangeDN ) if( $OldMailbox.EmailAddressPolicyEnabled ) { foreach( $EmailAddress in $OldMailbox.EmailAddresses ) { if( $EmailAddress -like 'smtp:*' ) { $EmailAddresses += $EmailAddress.ToString().ToLower() } else { $EmailAddresses += $EmailAddress.ToString() } } $parameters.add( 'EmailAddresses', @{Add=$EmailAddresses} ) } else { foreach( $EmailAddress in $OldMailbox.EmailAddresses ) { $EmailAddresses += $EmailAddress.ToString() } $parameters.add( 'EmailAddresses', $EmailAddresses ) } $parameters.add( 'DisplayName', $OldMailbox.DisplayName ) $parameters.add( 'Alias', $OldMailbox.Alias ) $parameters.add( 'CustomAttribute1', $OldMailbox.CustomAttribute1 ) $parameters.add( 'CustomAttribute2', $OldMailbox.CustomAttribute2 ) $parameters.add( 'CustomAttribute3', $OldMailbox.CustomAttribute3 ) $parameters.add( 'CustomAttribute4', $OldMailbox.CustomAttribute4 ) $parameters.add( 'CustomAttribute5', $OldMailbox.CustomAttribute5 ) $parameters.add( 'CustomAttribute6', $OldMailbox.CustomAttribute6 ) $parameters.add( 'CustomAttribute7', $OldMailbox.CustomAttribute7 ) $parameters.add( 'CustomAttribute8', $OldMailbox.CustomAttribute8 ) $parameters.add( 'CustomAttribute9', $OldMailbox.CustomAttribute9 ) $parameters.add( 'CustomAttribute10', $OldMailbox.CustomAttribute10 ) $parameters.add( 'CustomAttribute11', $OldMailbox.CustomAttribute11 ) $parameters.add( 'CustomAttribute12', $OldMailbox.CustomAttribute12 ) $parameters.add( 'CustomAttribute13', $OldMailbox.CustomAttribute13 ) $parameters.add( 'CustomAttribute14', $OldMailbox.CustomAttribute14 ) $parameters.add( 'CustomAttribute15', $OldMailbox.CustomAttribute15 ) $parameters.add( 'ExtensionCustomAttribute1', $OldMailbox.ExtensionCustomAttribute1 ) $parameters.add( 'ExtensionCustomAttribute2', $OldMailbox.ExtensionCustomAttribute2 ) $parameters.add( 'ExtensionCustomAttribute3', $OldMailbox.ExtensionCustomAttribute3 ) $parameters.add( 'ExtensionCustomAttribute4', $OldMailbox.ExtensionCustomAttribute4 ) $parameters.add( 'ExtensionCustomAttribute5', $OldMailbox.ExtensionCustomAttribute5 ) Write-Verbose ( 'Updating mailuser "{0}"' -f $OldMailbox.DistinguishedName ) set-mailuser @parameters } } elseif( $OldMailbox.Count -gt 1 ) { Write-Host ( 'Multiple mailboxes found for "{0}"' -f $Identity ) -ForegroundColor Red } else { Write-Host ( 'Unable to find mailbox for "{0}"' -f $Identity ) -ForegroundColor Red } }