Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 863
  • Last Modified:

Exchange 2007 PowerShell commmand to move mailbox to .pst AND delete the mailbox from AD?

Hello,
Hoping to find a PowerShell command to export a user's mailbox to a .pst AND delete the mailbox from AD. I've tried -DeleteContent -verbose and it seems to delete all the mail, but leave the mailbox. Ultimately I want to run this command on all users in an OU.
Thank you.
0
adamant40
Asked:
adamant40
  • 3
  • 3
2 Solutions
 
Rajith EnchiparambilOffice 365 & Exchange ArchitectCommented:
export-mailbox -identity username -pstfolderpath c~:\user.pst

remove-mailbox -identity username
0
 
adamant40Author Commented:
Hi Rajith,
My goal is to be able to run this on mailboxes in an OU. Could you give me the specific command structure for exporting all the mailboxes in OU Test to .pst files and deleting the mailboxes from AD? I've tried a few different ways of implementing your command but have not succeeded. Thank you.
0
 
Rajith EnchiparambilOffice 365 & Exchange ArchitectCommented:
get-mailbox -organizationalunit ouname | export-mailbox -pstfolderpath c~:\user.pst
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
adamant40Author Commented:
Hi Rajith,
get-mailbox -organizationalunit ouname | export-mailbox -pstfolderpath c~:\user.pst is the command I use to export all the mailboxes into .pst files. BUt it doesn't delete the mailbox from the mail store. Is there one command to do that? If not, is there a command to delete all mailboxes in an OU?
I could run get-mailbox -organizationalunit ouname | export-mailbox -pstfolderpath c~:\user.pst first, then the 2nd command to delete the mailboxes. That would be almost as good. Thank you.
0
 
gupnitCommented:
Hi,
Here are your commands:
  • Export all Mailboxes in OU:Get-Mailbox -OrganizationalUnit YOUROU | Export-Mailbox -PSTFolderPath C:\PSTFiles
  • Delete All Mailboxes & Account in OU: ForEach ($mbx in Get-Mailbox -OrganizationalUnit YOUROU) { Remove-Mailbox -Identity $mbx -Permanent}
Let me know
Thanks
Nitin Gupta (gupnit)
0
 
Rajith EnchiparambilOffice 365 & Exchange ArchitectCommented:
Simple command.

get-mailbox -organizationalunit ouname | remove-mailbox -confirm:$false

Give $true if you want to be prompted for approval.
0
 
adamant40Author Commented:
This was great information and worked with minor tweaking. Thanks all.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now