12

Using PowerShell To List All The Fonts In A Word Document

 2 years ago
source link: https://thomasrayner.ca/using-powershell-to-list-all-the-fonts-in-a-word-document/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Using PowerShell To List All The Fonts In A Word Document

Recently I was challenged by a coworker to use PowerShell to list all the fonts in a Word document. It turned out to be easier than I thought it would be… but also slower than I thought it would be. Here’s what I came up with.

$Word = New-Object -ComObject Word.Application
$OpenDoc = $Word.Documents.open('c:\temp\test.docx')
$OpenDoc.words | % { $_ | select -ExpandProperty font } | select Name -Unique
$OpenDoc.close()
$Word.quit()

There could very well be a better way of doing this but this is what I came up with in a hurry. Line 1 declares a new instance of Word and line 2 opens the document we’re looking at. Then, for each word (which is handily a property of the open word document), we’re expanding the font property and selecting all the unique names of the fonts on line 3. Lines 4 and 5 close the document and quit Word.

So you can get something like this!

Written on October 5, 2016

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK