我正在做一个涉及阅读大量 Outlook.pst 文件的项目。
这些文件都受密码保护,但我的密码有问题。问题是在 Outlook 中打开每个文件并输入密码以读取数据是非常繁琐的过程。
现在我在想是否有任何方法可以创建一个脚本,它会自动为我打开每个 .pst 文件,输入密码并在没有密码的情况下再次保存文件。
我一直在谷歌搜索,似乎没有找到任何解决我的问题的方法,看起来 MAPI outlook.application 接口的文档记录很差。到目前为止,我已经看到一个 PowerShell 脚本使用technet的 Excel 应用程序执行此操作
$comments = @'
Script name: Remove-Password.ps1
Created on: Tuesday, July 03, 2007
Author: Kent Finkle
Purpose: How can I use Windows Powershell to
Remove the Password When Opening an Excel Spreadsheet?
'@
#-----------------------------------------------------
function Release-Ref ($ref) {
([System.Runtime.InteropServices.Marshal]::ReleaseComObject(
[System.__ComObject]$ref) -gt 0)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
}
#-----------------------------------------------------
$xl = new-object -comobject excel.application
$xl.Visible = $True
$xl.DisplayAlerts = $False
$wb = $xl.Workbooks.Open("C:\Scripts\Test.xls",0,$False,1,"%reTG54w")
$wb.Password = ""
$a = $wb.SaveAs( "C:\Scripts\Test.xls")
$a = Release-Ref($wb)
$a = Release-Ref($xl)
可能我可以将其应用于 MAPI 与此类似的东西
$outlook = new-object -com outlook.application;
$ns = $outlook.GetNameSpace("MAPI");
$fSaveMe = $ns.GetDefaultFolder($olFolderInbox).Folders.Item("Save Me")
$fSaveMe.Items | foreach { [void]$_.Move($ns.Folders.Item("Legal")) }
有没有人遇到过类似的问题?潜在的解决方案不必在 PowerShell 中,它可以在 Python、Perl、Java、C# 或任何东西中,只要它能完成工作:)