1

嗨,我正在尝试通过 powershell 删除为“.doc、.docx、.pptx”文档设置的“隐藏数据”和个人信息:这是我为此编写的 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 条记录,我希望从中删除“隐藏的文档信息”。提前致谢。

4

1 回答 1

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()
于 2013-08-19T09:45:32.497 回答