This PowerShell Module allows you to create Microsoft Word (.docx) document without Microsoft Word installed. That basically means you can create Word documents on servers, or shared workstations without Microsoft Office. It also means it can be run in background and doesn't require any COM objects.

Note worthy features
Allows Microsoft Word documents to be created in PowerShell
Doesn't require Microsoft Word to be installed
Fairly easy to use
No license needed. Free to use.
Open source
Useful links
Code is published on GitHub
Issues should be reported on GitHub
Code is published as a module on PowerShellGallery
Code is published as a zip file on Microsoft Script Gallery

PSWriteWord utilizes an open source module DocX (where commercial brother is called Xceed Words for .NET) that's available on GitHub. Originally this C# library was created by Cathal Coffey and later on maintained by me (Przemysław Kłys – LinkedIn). It was however in slow development so both Cathal and I decided to let the project go into more capable hands with support and further features getting added (slowly but each new version adds some stuff – commercial version is few versions ahead of the free one). Old C# Library (that I took a part in) is still available on GitHub under Classic Branch

Related articles
New version (0.5.1), PSWriteWord – Add-WordTable expanded / Format-TransposeTable added – lots of diff fixes/features…
New version (0.4.6), PSWriteWord – Add-WordTable / Add-WordText Expanded
New version (0.4.1), Add-WordTable Examples, breaking changes, and lots of things added
But what is it actually?

Well.. have you ever got a request for help with creating multiple word documents based on dynamic data? Maybe you want to create some simple Invoice or send a new agreement to all employees based on their AD data… well now you can. While this method was available for long time (and I've utilized it for many of my apps in C# / .NET) it is now possible to do in PowerShell. No compilation, no exe, should work on any newer Windows system (.NET Core is still not supported by module). Keep in mind that this is still work in progress…

  • Add-WordBarChart
  • Add-WordBookmark
  • Add-WordChartSeries
  • Add-WordCustomProperty
  • Add-WordEquation
  • Add-WordFooter
  • Add-WordHeader
  • Add-WordHyperLink
  • Add-WordImage
  • Add-WordLine
  • Add-WordLineChart
  • Add-WordList
  • Add-WordListItem
  • Add-WordPageBreak
  • Add-WordParagraph
  • Add-WordPicture
  • Add-WordPieChart
  • Add-WordProtection
  • Add-WordSection
  • Add-WordTable
  • Add-WordTableCellValue
  • Add-WordTableColumn
  • Add-WordTableRow
  • Add-WordTableTitle
  • Add-WordTabStopPosition
  • Add-WordText
  • Add-WordTOC
  • Add-WordTocItem
  • Copy-WordTable
  • Copy-WordTableRow
  • Format-WordListItem
  • Get-WordCustomProperty
  • Get-WordDocument
  • Get-WordFooter
  • Get-WordHeader
  • Get-WordListItemParagraph
  • Get-WordPageSettings
  • Get-WordParagraphForList
  • Get-WordParagraphs
  • Get-WordPicture
  • Get-WordSection
  • Get-WordTable
  • Get-WordTableRow
  • New-WordBlock
  • New-WordBlockList
  • New-WordBlockPageBreak
  • New-WordBlockParagraph
  • New-WordBlockTable
  • New-WordDocument
  • New-WordListItem
  • New-WordTable
  • New-WordTableBorder
  • Remove-WordParagraph
  • Remove-WordPicture
  • Remove-WordTable
  • Remove-WordTableColumn
  • Remove-WordTableRow
  • Remove-WordText
  • Save-WordDocument
  • Set-WordContinueFormatting
  • Set-WordHyperLink
  • Set-WordList
  • Set-WordMargins
  • Set-WordOrientation
  • Set-WordPageSettings
  • Set-WordPageSize
  • Set-WordParagraph
  • Set-WordPicture
  • Set-WordTable
  • Set-WordTableAutoFit
  • Set-WordTableBorder
  • Set-WordTableCell
  • Set-WordTableCellFillColor
  • Set-WordTableCellShadingColor
  • Set-WordTableColumnWidth
  • Set-WordTableColumnWidthByIndex
  • Set-WordTableDesign
  • Set-WordTableDirection
  • Set-WordTablePageBreak
  • Set-WordTableRowMergeCells
  • Set-WordText
  • Set-WordTextAlignment
  • Set-WordTextBold
  • Set-WordTextCapsStyle
  • Set-WordTextColor
  • Set-WordTextDirection
  • Set-WordTextFontFamily
  • Set-WordTextFontSize
  • Set-WordTextHeadingType
  • Set-WordTextHidden
  • Set-WordTextHighlight
  • Set-WordTextIndentationFirstLine
  • Set-WordTextIndentationHanging
  • Set-WordTextItalic
  • Set-WordTextKerning
  • Set-WordTextLanguage
  • Set-WordTextMisc
  • Set-WordTextPercentageScale
  • Set-WordTextPosition
  • Set-WordTextScript
  • Set-WordTextShadingType
  • Set-WordTextSpacing
  • Set-WordTextSpacingAfter
  • Set-WordTextSpacingBefore
  • Set-WordTextStrikeThrough
  • Set-WordTextText
  • Set-WordTextUnderlineColor
  • Set-WordTextUnderlineStyle

Some of those commands are not yet finished and some are going to evolve. Some will get new features, some will be deprecated (or not really needed).

Simple example

Below is one of the simplest examples. You define path to new file, you define new WordDocument and use special command Add-WordText which contains lots of possible options. You will be using this command a lot. Finally we save document.

Import-Module PSWriteWord #-Force

$FilePath = "$Env:USERPROFILE\Desktop\PSWriteWord-Example-CreateWord1.docx"

### define new document
$WordDocument = New-WordDocument $FilePath
### add 3 paragraphs
Add-WordText -WordDocument $WordDocument -Text 'This is a text' -FontSize 10
Add-WordText -WordDocument $WordDocument -Text 'This is a text font size 21' -FontSize 21
Add-WordText -WordDocument $WordDocument -Text 'This is a text font size 15' -FontSize 15
### Save document
Save-WordDocument $WordDocument

### Start Word with file
Invoke-Item $FilePath

PSWriteWord-CreateWord1

Notice how it created 3 paragraphs in 1 second. Also notice how Word marked all text red because the language of the document was not set so it took defaults from my Word setup. Keep in mind it doesn't need Word installed. It doesn't open Microsoft Word in background. It works on the XML level.

Simple example #2

Below example adds saving with language set for all text to ‘en-US' culture. It also adds some underlining and sets Heading Type.

Import-Module PSWriteWord #-Force

$FilePath = "$Env:USERPROFILE\Desktop\PSWriteWord-Example-CreateWord4.docx"

$WordDocument = New-WordDocument $FilePath

Add-WordText -WordDocument $WordDocument -Text 'This is a text' -FontSize 10 -SpacingBefore 50 -UnderlineStyle singleLine -Supress $True
Add-WordText -WordDocument $WordDocument -Text 'This is a text' -FontSize 10 -SpacingBefore 15 -Bold $true -Supress $True
Add-WordText -WordDocument $WordDocument -Text 'This is a text with Heading type 3' -FontSize 15 -HeadingType Heading3 -FontFamily 'Arial' -Italic $true

Save-WordDocument $WordDocument -Language 'en-US'

### Start Word with file
Invoke-Item $FilePath

PSWriteWord-CreateWord4

Charts example

Another example shows how to create Pie Chart.

Import-Module PSWriteWord #-Force

$FilePath = "$Env:USERPROFILE\Desktop\PSWriteWord-Example-CreateCharts1.docx"

$WordDocument = New-WordDocument $FilePath
Add-WordText -WordDocument $WordDocument -Text 'Pie Chart Example #1' `
    -FontSize 15 `
    -Color Blue `
    -Bold $true -HeadingType Heading1

Add-WordPieChart -WordDocument $WordDocument -ChartName 'My finances' -Names 'Today', 'Yesterday', 'Two days ago' -Values 1050.50, 2000, 20000 -ChartLegendPosition Bottom -ChartLegendOverlay $false

Add-WordText -WordDocument $WordDocument -Text 'Pie Chart Example #2' `
    -FontSize 15 `
    -Color Blue `
    -Bold $true -HeadingType Heading1

Add-WordPieChart -WordDocument $WordDocument -ChartName 'My finances' -Names 'Today', 'Yesterday' -Values  2000, 20000 -ChartLegendPosition Left -ChartLegendOverlay $true

Save-WordDocument $WordDocument -Language 'en-US'

### Start Word with file
Invoke-Item $FilePath

As you can see 2 Charts are added to Word Document, language is set to ‘en-US' and 2 headings are created. All that with just few lines of code.

PSWriteWord-CreateCharts1

Required prerequisites

Before you are able to use this script you need to do few manual steps. Since this script is published as module… it's quite easy to set this up. Just execute command below (accept warnings) .. and start creating Microsoft Word document in PowerShell.

Install-Module PSWriteWord

#Update-Module PSWriteWord

You can of course install everything manually from GitHub (as everything is published there) but it will be far easier to just use Install-Module.

Quick fixes / helpful tips

This is a unique website which will require a more modern browser to work! Please upgrade today!