Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions Links


SQL Server DBA Jobs

Powershell write to Word document

12 February,2013 by Tom Collins

Question: I need to create  a snapshot of server cpu  information and write into a Microsoft Word Document using Powershell . I’ve read   the Powershell to HTML - SQL Server DBA  post , but the requirement is to output to a  Word Document.

I already have the code to iterate through the server list. The missing part is once on the server , obtaining the server cpu information , creating the Word document and writing into the Word document

Answer: The script below is a template for obtaining server information , creating the Microsoft Word document with a combject and  writing to the Word document with Powershell.

In this example – the $cpu_usage variable capture the current CPU usage. In a similar way you can obtain memory and disk usage details


$cpu = gwmi –computername $Server win32_Processor 
$cpu_usage = "{0:0.0} %" -f $cpu.LoadPercentage 

$word = New-Object -ComObject "Word.application"
$doc = $word.Documents.Add()
$word.Selection.TypeText("CPU Percentage: $cpu_usage")
$file = "C:\projects\testing\laboratory\test.doc"

 Read More

How to Convert Microsoft Word Format to HTML using Powershell

Export-CSV Powershell

SQL Server – Powershell Excel to HTML

Powershell , Excel charts and data presentation

Author: Tom Collins (


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on Powershell write to Word document | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer