您好我正试图通过powershell删除'.doc,.docx,.pptx'文档中设置的'隐藏数据'和个人信息: HEre是我为此编写的powershell脚本:
$path = "C:\Users\anisjain\Documents\GRR Production\HiddenProrerties"
Add-Type -AssemblyName Microsoft.Office.Interop.Word
$xlRemoveDocType = "Microsoft.Office.Interop.xlRDIRemovePersonalInformation" -as [type]
$wordFiles = Get-ChildItem -Path $path -include *.doc, *.docx -recurse
$objword = New-Object -ComObject word.application
foreach($obj in $wordFiles)
{
$documents = $MSWord.Documents.Open($obj.fullname)
"Removing document information from $obj"
$documents.RemoveDocumentInformation($xlRemoveDocType::xlRDIRemovePersonalInformation)
$documents.Save()
$objword.documents.close()
}
$objword.Quit()
然而,这不起作用。有人可以告诉我哪里出错了?
如果还有其他方法可以做到这一点。我有大约2000条记录,我希望从中删除“隐藏文档信息”。提前致谢。
答案 0 :(得分:4)
这是一个适用于我的脚本,经过一些谷歌搜索/复制/修改
$path = "d:\rubbish\myfolder\"
Add-Type -AssemblyName Microsoft.Office.Interop.Word
$WdRemoveDocType = "Microsoft.Office.Interop.Word.WdRemoveDocInfoType" -as [type]
$wordFiles = Get-ChildItem -Path $path -include *.doc, *.docx -recurse
$objword = New-Object -ComObject word.application
$objword.visible = $false
foreach($obj in $wordFiles)
{
$documents = $objword.Documents.Open($obj.fullname)
"Removing document information from $obj"
# WdRemoveDocInfoType Enumeration Reference
# http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdremovedocinfotype(v=office.14).aspx
# 99 = WdRDIAll
#$documents.RemoveDocumentInformation(99)
$documents.RemoveDocumentInformation($WdRemoveDocType::wdRDIAll)
$documents.Save()
$objword.documents.close()
}
$objword.Quit()