How to delete Imported PST folder from the Mailbox powersehll

I have imported PST into mailbox with below command for specific  folder like RecoverdFiles.

New-MailboxImportRequest -Mailbox TestUser –filepath \\exchange\C$\Mike.pst -TargetRootFolder "RecoveredFiles"

Is there any powershell command to delete imported PST folder ?
Ali-Raza111Asked:
Who is Participating?
 
Hasin Ahmed ChoudharyConnect With a Mentor Exchange AdministratorCommented:
Hello Ali,

You have imported the PST into target folder "RecoveredFiles". There is no PS cmdlet available which will search folder and delete it.

If you need to do it for one mailbox, just take full access and delete the top folder "RecoveredFiles" under which PST was imported.Unless you want to complicate the thing and write EWS script to do that. Ref below:

https://social.technet.microsoft.com/Forums/windowsserver/en-US/bc07df23-64f1-4732-a399-76fd39b1595e/powershell-exchange-2010-delete-folder-in-mailbox-or-delete-mail-in-certain-folder?forum=winserverpowershell
0
 
Hello ThereConnect With a Mentor System AdministratorCommented:
This will disconnect the PST:
$Outlook = new-object -com outlook.application 
$Namespace = $Outlook.getNamespace("MAPI")
$PSTtoDelete = "c:\test\pst.pst"
$PST = $namespace.Stores | ? {$_.FilePath -eq $PSTtoDelete}
$PSTRoot = $PST.GetRootFolder()
$PSTFolder = $namespace.Folders.Item($PSTRoot.Name)
$namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$namespace,($PSTFolder)

Open in new window

0
 
Ali-Raza111Author Commented:
I would like to delete the imported PST folder from the User mailbox? Need to get the powershell command to perform the task.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
Hello ThereSystem AdministratorCommented:
Save the code as ps1 and run it remotely...
0
 
Mal OsborneAlpha GeekCommented:
Can't quite work out what you are trying to do here.

If you want to delete the original  .PST file you just imported from then just use DEL.  Most standard DOS commands work in Powershell.
0
 
Ali-Raza111Author Commented:
@Mal Osborne, Can you please elaborate more USE DEL?
0
 
Mal OsborneAlpha GeekCommented:
DEL \\exchange\C$\Mike.pst
0
 
Ali-Raza111Author Commented:
You mean like this?

Get-Mailbox TestUser -Delete –filepath \\exchange\C$\Mike.pst -TargetRootFolder "RecoveredFiles"
0
 
Hello ThereSystem AdministratorCommented:
What do you want to achieve? Delete it from Outlook or from computer?
0
 
Ali-Raza111Author Commented:
I'm trying to delete from the User Mailbox from Exchange Powersehll
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.