2014年12月4日木曜日

PowerShellでExcel/Wordの個人情報を消去する


Officeのファイルを編集したとき、「最終保存者」が必ず付いてしまう。
それをPowerShellで消去する方法。





[Excel]の個人情報を削除する
参考元:http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/07/use-powershell-to-remove-personal-information-from-excel.aspx

$path = "c:\fso" Add-Type -AssemblyName Microsoft.Office.Interop.Excel $xlRemoveDocType = "Microsoft.Office.Interop.Excel.XlRemoveDocInfoType" -as [type] $excelFiles = Get-ChildItem -Path $path -include *.xls, *.xlsx -recurse $objExcel = New-Object -ComObject excel.application $objExcel.visible = $false foreach($wb in $excelFiles) {  $workbook = $objExcel.workbooks.open($wb.fullname)
 "Removing document information from $wb" 
 $workbook.RemoveDocumentInformation($xlRemoveDocType::xlRDIAll)  $workbook.Save()  $objExcel.Workbooks.close() } $objExcel.Quit()



[Word]の個人情報を削除する
参考元:http://stackoverflow.com/questions/17190487/removing-hidden-data-and-personal-information-from-doc-docx-and-pptx

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


以上。

0 件のコメント:

コメントを投稿