N00b2015
asked on
Remove all hidden metadata properties of MS .Docx Files
Hi All,
I'm trying to use powershell to remove all the file properties of numerous documents I have (docx). I've managed to dig up a script (below) which works really well however, it doesn't seem to clear the Content Created, Date Last Saved and File information such as Date Created, Date Modified and Date accessed. It does however remove the Authors information only. Is someone able to help??
I'm trying to use powershell to remove all the file properties of numerous documents I have (docx). I've managed to dig up a script (below) which works really well however, it doesn't seem to clear the Content Created, Date Last Saved and File information such as Date Created, Date Modified and Date accessed. It does however remove the Authors information only. Is someone able to help??
$path = "C:\Test"
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()
ASKER
Thanks very much xtermie. I'd prefer to do this all via Powershell if possible? The thought of the many docs opening for this to happen sounds painful. Any ideas?
There's a DLL specifically written for this
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've not had any luck in this. I'm at a point that I would use any other methods other than just powershell but possible not the use of Macro's. Also, thank you very much for your assistance Bill :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks all. I guess that's that then :)
Sub CleanProp()
Dim oProp As DocumentProperty
On Error Resume Next
For Each oProp In ActiveDocument.BuiltInDocu
oProp.Value = ""
ActiveDocument.Save
Next oProp
End Sub
Try in one document and if it works include above in a macro that opens all docs in a folder, removes doc properties and saves them like below
Sub DoVBRoutineNow()
Dim file
Dim path As String
path = "C:\myWorkFolder\" 'specify your folder
file = Dir(path & "*.docx")
Do While file <> ""
Documents.Open FileName:=path & file
Call CleanProp
ActiveDocument.Save
ActiveDocument.Close
file = Dir()
Loop
End Sub