8.09.2016

Exchange 2016 Powershell Script to Remove the Mailbox but leave the user account

Exchange 2016 Powershell Script to Remove the Mailbox but leave the user account

Below is a powershell command that I wrote to prompt the user for a mailbox to delete and then to prompt again if you are finished. I was using this to delete and re-do with the GWAVA copy transfer process.

Import-Module ActiveDirectory
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

function Show-Menu
{
     param (
           [string]$Title = 'Delete Mailbox Only'
     )
     #cls
     Write-Host "================ $Title ================"
   
     Write-Host "Q: Press 'Q' to quit."
}





do
{
     $username = Read-Host -Prompt 'Input the username'
     Disable-Mailbox -Identity $username -Confirm:$false
   
     Write-Host "The User Mailbox '$username' has been deleted"
         
     Show-Menu
     $input = Read-Host "Please make a selection"
     switch ($input)
     {
         
           'q' {
                return
           }
     }
     pause
}
until ($input -eq 'q')

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.