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() $doc.Activate() $word.Selection.TypeText("CPU Percentage: $cpu_usage") $word.Selection.TypeParagraph() $file = "C:\projects\testing\laboratory\test.doc" $doc.SaveAs([REF]$file) $Word.Quit()
How to Convert Microsoft Word Format to HTML using Powershell
SQL Server – Powershell Excel to HTML
Powershell , Excel charts and data presentation
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |