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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hello ThereSystem 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
Hello ThereSystem AdministratorCommented:
Save the code as ps1 and run it remotely...
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
Hasin Ahmed ChoudharyExchange 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.