I have a folder with sub folders and I want to run a powershell script that finds all the office documents (word and excel 2003,2007 and 2010 for the moment) and print the "last saved by" property that we can find on the properties, details tab of the files.
Can anybody help?
--- solution ---
$word = New-Object -Com Word.Application
$word.Visible = $false #to prevent the document you open to show
$doc = $word.Documents.Open($path)
$binding = "System.Reflection.BindingFlags" -as [type]
Foreach($property in $doc.BuiltInDocumentProperties) {
try {
$pn = [System.__ComObject].invokemember("name",$binding::GetProperty,$null,$property,$null)
if ($pn -eq "Last author") {
$lastSaved = [System.__ComObject].invokemember("value",$binding::GetProperty,$null,$property,$null)
write-host "Last saved by: "$lastSaved
} }
catch { }
}
$doc.Close()
$word.Quit()
Did some adjustments to the correct answer and now it's working.