Let's assume you have a bunch of Word files and would like to know how much pages they contain. Here is a function that takes the path to one Word file and determines its page count:
#requires -Version 1
# adjust path to point to an existing Word file:
$Path = "C:\...\SomeChapter.doc"
$word = New-Object -ComObject Word.Application
$word.Visible = $true
$binding = 'System.Reflection.BindingFlags' -as [type]
$doc = $word.Documents.Open($Path)
$prop = $doc.BuiltInDocumentProperties(14)
$pages = [System.__ComObject].invokemember('value',$binding::GetProperty,$null,$prop,$null)
"$Path has $Pages pages."
If it works for you, turn it into a function so you can use PowerShell to sum up the pages of many Word documents.
Throughout this month, we'd like to point you to two awesome community-driven global PowerShell events taking place this year:
Europe: April 20-22: 3-day PowerShell Conference EU in Hannover, Germany, with more than 30+ speakers including Jeffrey Snover and Bruce Payette, and 60+ sessions (www.psconf.eu).
Asia: October 21-22: 2-day PowerShell Conference Asia in Singapore. Watch latest annoncements at www.psconf.asia
Both events have limited seats available so you may want to register early.
ReTweet this Tip!
how does this work for more than one document in a directory?
I've been trying to do this for a couple of weeks. All the pages I have found have been wrong. Their suggestions just produce big red error message. Your method works beautifully. Thank you very much for sharing it.