Exchange_Convert_To_SharedMailbox.ps1

function Exchange-ConvertToSharedMailbox {
    param(
        [string]$Identity
    )

    $mailbox = Get-Mailbox -Identity $Identity -ErrorAction SilentlyContinue
    if (!$mailbox) {
        Write-Host "Mailbox '$Identity' not found."
        return
    }

    if ($mailbox.RecipientTypeDetails -eq "UserMailbox") {
        Set-Mailbox -Identity $Identity -Type Shared

        $sharedMailbox = Get-Mailbox -Identity $Identity
        $userToAdd = "username@example.com"
        Add-MailboxPermission -Identity $sharedMailbox -User $userToAdd -AccessRights FullAccess -AutoMapping $false

        Write-Host "Mailbox '$Identity' has been converted to a shared mailbox."
    } else {
        Write-Host "Mailbox '$Identity' is not a regular mailbox. Cannot convert to a shared mailbox."
    }
    }