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.
adamant40Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Rajith EnchiparambilConnect With a Mentor Office 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
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
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
 
gupnitConnect With a Mentor Commented:
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
All Courses

From novice to tech pro — start learning today.