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

Posted on 2009-05-12
Last Modified: 2012-05-06
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.
Question by:adamant40
  • 3
  • 3
LVL 24

Accepted Solution

Rajith Enchiparambil earned 250 total points
ID: 24369592
export-mailbox -identity username -pstfolderpath c~:\user.pst

remove-mailbox -identity username

Author Comment

ID: 24369832
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.
LVL 24

Expert Comment

by:Rajith Enchiparambil
ID: 24369915
get-mailbox -organizationalunit ouname | export-mailbox -pstfolderpath c~:\user.pst
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).


Author Comment

ID: 24369967
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.
LVL 32

Assisted Solution

gupnit earned 250 total points
ID: 24371388
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
Nitin Gupta (gupnit)
LVL 24

Expert Comment

by:Rajith Enchiparambil
ID: 24372170
Simple command.

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

Give $true if you want to be prompted for approval.

Author Closing Comment

ID: 31580735
This was great information and worked with minor tweaking. Thanks all.

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now