如何使用Powershell从Outlook断开PST文件? [英] How to disconnect PST file from Outlook using Powershell?

查看:211
本文介绍了如何使用Powershell从Outlook断开PST文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图编写一个脚本来断开PST文件与Outlook的连接.

I'm trying to write a script to disconnect PSTs files from Outlook.

我一直在尝试这样的事情:

I've been trying with something like this:

$Outlook = new-object -com outlook.application 
$Namespace = $Outlook.getNamespace("MAPI")

$PSTtoDelete = "c:\test\pst.pst"

$Namespace.RemoveStore($PSTtoDelete)

我收到以下错误:

找不到"RemoveStore"的重载和参数计数为"1".

"Cannot Find overload for "RemoveStore" and the argument count "1".

我还尝试了与此不同的解决方案(在此处找到 http://www.mikepfeiffer.net/2013/04/how-to-test-outlook-pst-personal-folder-file-access-with-powershell/):

I also tried a different solution with this (found here http://www.mikepfeiffer.net/2013/04/how-to-test-outlook-pst-personal-folder-file-access-with-powershell/) :

$namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$namespace,($PSTFolder))

我查看了技术文档,如果我正确理解RemoveStore方法需要一个文件夹.

I took a look to the technect documentations and if I understand properly the RemoveStore Method expects a Folder.

如果有人可以给我一个提示,将不胜感激!

If anyone would be able to give me a hint on this one that would be greatly appreciated!

谢谢!

推荐答案

根据您的链接,脚本需要附加的PST的 Name ,而不是路径.试试这个:

According to your link the script expects Name of the attached PST, not the path. Try this:

$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))

这篇关于如何使用Powershell从Outlook断开PST文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆