Blog Post Title Four
<#
.SYNOPSIS
Convert an Exchange on-prem mailbox between UserMailbox and SharedMailbox.
.DESCRIPTION
- Prompts for an email address / identity
- Validates recipient exists
- Displays recipient type details and a best-effort "On-Prem vs Office 365" indicator
- Prompts to convert to Shared or User mailbox
- Converts only when needed
.NOTES
Run from Exchange Management Shell on Exchange SE (on-prem).
#>
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Resolve-RecipientIdentity {
param(
[Parameter(Mandatory)]
[string]$Identity
)
try { Get-Recipient -Identity $Identity -ErrorAction Stop } catch { $null }
}
function Get-MailboxObject {
param(
[Parameter(Mandatory)]
[string]$Identity
)
try { Get-Mailbox -Identity $Identity -ErrorAction Stop } catch { $null }
}
Write-Host ""
Write-Host "Exchange SE Mailbox Type Converter (UserMailbox <-> SharedMailbox)" -ForegroundColor Cyan
Write-Host "-------------------------------------------------------------------"
Write-Host ""
$identity = Read-Host "Enter the user's email address (or other identity such as alias/UPN/DN)"
if ([string]::IsNullOrWhiteSpace($identity)) { Write-Host "No input provided. Exiting." -ForegroundColor Yellow; return }
$recipient = Resolve-RecipientIdentity -Identity $identity
if (-not $recipient) { Write-Host "Recipient not found for identity: $identity" -ForegroundColor Red; return }
Write-Host ""
Write-Host "Recipient found:" -ForegroundColor Green
Write-Host (" DisplayName : {0}" -f $recipient.DisplayName)
Write-Host (" PrimarySmtpAddress : {0}" -f $recipient.PrimarySmtpAddress)
Write-Host (" RecipientType : {0}" -f $recipient.RecipientType)
Write-Host (" RecipientTypeDetails : {0}" -f $recipient.RecipientTypeDetails)
$locationHint = "On-Prem (local)"
if ($recipient.RecipientTypeDetails -match '^Remote') { $locationHint = "Office 365 (remote/hybrid)" }
elseif ($recipient.RecipientTypeDetails -in @('UserMailbox','SharedMailbox','RoomMailbox','EquipmentMailbox')) { $locationHint = "On-Prem (local)" }
Write-Host (" Mailbox location hint : {0}" -f $locationHint)
$mailbox = Get-MailboxObject -Identity $recipient.Identity
if (-not $mailbox) {
Write-Host ""
Write-Host "This recipient is not a local on-prem mailbox that can be converted with Set-Mailbox -Type." -ForegroundColor Yellow
Write-Host "If this is an Office 365 (remote) mailbox, convert it in Exchange Online (or use the appropriate hybrid approach)." -ForegroundColor Yellow
return
}
$currentType = [string]$mailbox.RecipientTypeDetails
if ($currentType -notin @('UserMailbox','SharedMailbox')) {
Write-Host ""
Write-Host ("This mailbox type is '{0}'. This script only converts UserMailbox <-> SharedMailbox." -f $currentType) -ForegroundColor Yellow
return
}
Write-Host ""
Write-Host ("Current mailbox type: {0}" -f $currentType) -ForegroundColor Cyan
Write-Host ""
do {
$choice = Read-Host "Convert to (S)hared or (U)ser? Enter S or U"
$choice = $choice.Trim().ToUpperInvariant()
} while ($choice -notin @('S','U'))
$desiredRecipientTypeDetails = if ($choice -eq 'S') { 'SharedMailbox' } else { 'UserMailbox' }
if ($desiredRecipientTypeDetails -eq $currentType) {
Write-Host ""
Write-Host ("No change needed. Mailbox is already a {0}." -f $currentType) -ForegroundColor Green
return
}
# FIX: Use Set-Mailbox -Type values (Shared/Regular) and pass a plain string identity to avoid SerializationData errors
$setMailboxType = if ($desiredRecipientTypeDetails -eq 'SharedMailbox') { 'Shared' } else { 'Regular' }
$mbxIdentity = $mailbox.PrimarySmtpAddress.ToString() # alternatively: $mailbox.Guid.ToString()
Write-Host ""
Write-Host ("About to convert mailbox '{0}' ({1}) from {2} to {3}." -f $mailbox.DisplayName, $mbxIdentity, $currentType, $desiredRecipientTypeDetails) -ForegroundColor Yellow
$confirm = Read-Host "Proceed? (Y/N)"
if ($confirm.Trim().ToUpperInvariant() -ne 'Y') { Write-Host "Cancelled." -ForegroundColor Yellow; return }
try {
Set-Mailbox -Identity $mbxIdentity -Type $setMailboxType -Confirm:$false
Write-Host ""
Write-Host "Conversion complete. Verifying..." -ForegroundColor Green
$verify = Get-Mailbox -Identity $mbxIdentity -ErrorAction Stop
Write-Host (" New RecipientTypeDetails: {0}" -f $verify.RecipientTypeDetails) -ForegroundColor Green
}
catch {
Write-Host ""
Write-Host ("Conversion failed: {0}" -f $_.Exception.Message) -ForegroundColor Red
throw
}

