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

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

问题描述

我正在尝试编写一个脚本来断开 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:	estpst.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 的名称,而不是路径.试试这个:

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:	estpst.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 断开 PST 文件与 Outlook 的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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