Outlook Powershell脚本

问题描述:

我一直在做一些挖掘并试图找到一种方法来从脚本中删除PST的Outlook。我不完全知道如何编写脚本,但我正在努力学习。我发现这个旧的*,但我不确定如何实际输入我需要的信息。Outlook Powershell脚本

How to disconnect PST file from Outlook using Powershell?

有问题的脚本如下。

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

我知道第三行,在哪里输入PST本身的文件路径,但我不知道该输入剩余行的内容。

我知道这是一个总的新手问题,但任何帮助将超级赞赏。

谢谢!

+1

有你运行呢?你有错误吗?你有什么不明白? – ArcSet

+0

所以除了“c:\ test \ pst.pst”之外,这个脚本还有其他部分需要指向它的任何部分吗? –

+0

不知道。看起来不像它...运行,看看你得到了什么错误...这就是我们如何开始调试.... – ArcSet

这是一个功能我只是写希望它有助于

function Remove-OutlookStore($StoreFilePath){ 
    get-process | where { $_.Name -like "Outlook" }| kill 
    $Outlook = new-object -com outlook.application 
    $Namespace = $Outlook.GetNamespace("mapi") 
    $Store = $namespace.Stores | ?{$_.FilePath -like $StoreFilePath} | %{$_} 
    $namespace.RemoveStore($Store.GetRootFolder()) 
    get-process | where { $_.Name -like "Outlook" }| kill 
} 

Remove-OutlookStore -StoreFilePath C:\Test\Test.pst