Iain Brighton has created a free PowerShell module called „PScribo“ that can be used to easily create documents and reports in text, html, or Word format.

To use this module, simply run this command:

# https://github.com/iainbrighton/PScribo 
# help about_document 

# create a folder to store generated documents 
$OutPath = "c:\temp\out"
$exists = Test-Path -Path $OutPath
if (!$exists) { $null = New-Item -Path $OutPath -ItemType Directory -Force }


Document 'Report' {
Paragraph -Style Heading1 "System Inventory for $env:computername"
Paragraph -Style Heading2 'BIOS Information'
Paragraph 'BIOS details:' -Bold
$bios = Get-WmiObject -Class Win32_BIOS | Out-String
Paragraph $bios.Trim()
} |
Export-Document -Path $OutPath -Format Word,Html,Text

# open the generated documents 
explorer $OutPath

In the previous tip, we illustrated how you can add results from a cmdlet to a text report by converting the objects to plain text:

# https://github.com/iainbrighton/PScribo 
# help about_document 

# create a folder to store generated documents 
$OutPath = "c:\temp\out"
$exists = Test-Path -Path $OutPath
if (!$exists) { $null = New-Item -Path $OutPath -ItemType Directory -Force }


Document 'Report' {
Paragraph -Style Heading1 "System Inventory for $env:computername"
Paragraph -Style Heading2 'BIOS Information'
Paragraph 'BIOS details:' -Bold
$bios = Get-WmiObject -Class Win32_BIOS | Out-String
Paragraph $bios.Trim()
} |
Export-Document -Path $OutPath -Format Word,Html,Text

# open the generated documents 
explorer $OutPath

This is pretty straightforward but ugly. If you’d like to add object results as sophisticated tables, take a look at this approach:

# https://github.com/iainbrighton/PScribo 
# help about_document 

# create a folder to store generated documents 
$OutPath = "c:\temp\out"
$exists = Test-Path -Path $OutPath
if (!$exists) { $null = New-Item -Path $OutPath -ItemType Directory -Force }

# generate document 
Document 'BIOS' {
# get an object with rich information
$info = Get-WmiObject -Class Win32_BIOS

# find out the property names that have actual information
$properties = $info | Get-Member -MemberType *property |
Select-Object -ExpandProperty Name |
Where-Object { 

$info.$_ -ne $null -and $info.$_ -ne ''

} |
Sort-Object

# turn each property into a separate object
$infos = $properties | ForEach-Object { 
[PSCustomObject]@{
Name = $_
Value = $info.$_
}


}

Paragraph -Style Heading1 "BIOS Information"

# generate a table with one line per property
$infos |
# select the properties to display, and the header texts to use
Table -Columns Name,Value -Headers 'Item','Content' -Width 0

} |
Export-Document -Path $OutPath -Format Word

# open the generated documents 
explorer $OutPath

It basically creates new objects per object property, and displays these as table. The result is a detailed report about BIOS information.

Twitter This Tip! ReTweet this Tip!

Anonymous