Skip to content

Commit 5f782ba

Browse files
Added ReportUnit reporting for the pester tests to create and display a HTML report
1 parent 075e17d commit 5f782ba

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

Test-OLAInstance.ps1

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ function Test-OLAInstance
4444
4545
This will check that the SQL Agent is running on the servers returned from a query against the dbareports, That there are Ola Hallengren maintenance solution agent jobs on Server1,Server2 and Server3. That the
4646
jobs are enabled and have a schedule but not that they succeeeded. It also checks for the Server1,Server2 and Server3 folders in the share and the existence of the Database Restore Text File
47+
.EXAMPLE
48+
$Servers = (Invoke-Sqlcmd -ServerInstance dbareports -Database dbareports -Query "Select Servername from dbo.InstanceList where Environment = 'Development' and Inactive = 0 and NotContactable = 0").ServerName
49+
Test-OLAInstance -Instance $Servers -Report
50+
51+
This will check that the SQL Agent is running on the servers returned from a query against the dbareports, That there are Ola Hallengren maintenance solution agent jobs on Server1,Server2 and Server3. That the
52+
jobs are enabled and have a schedule but not that they succeeeded. It also checks for the Server1,Server2 and Server3 folders in the share and the existence of the Database Restore Text File
53+
It will also download the ReportUnit Exe if it doesnt exist and create an HTML Report
4754
4855
.NOTES
4956
AUTHOR - Rob Sewell https://sqldbawithabeard.com @SQLDBAWithBeard
5057
DATE - 07/09/2016
5158
#>
59+
#requires -Version 5
5260
#Requires -Modules Pester
5361
#Requires -Modules sqlserver
5462
[CmdletBinding()]
@@ -81,13 +89,13 @@ Param(
8189
[switch]$NoDatabaseRestoreCheck,
8290
# A switch to not perform the test if the Job succeeded
8391
[Parameter(Mandatory=$false)]
84-
[switch]$DontCheckJobOutcome
92+
[switch]$DontCheckJobOutcome ,
93+
# A switch to output a report HTML
94+
[Parameter(Mandatory=$false)]
95+
[switch]$Report
8596
)
8697

8798

88-
89-
90-
9199
$Path = 'Git:\Functions\Test-OLA.ps1'
92100
$Script = @{
93101
Path = $Path;
@@ -99,5 +107,30 @@ Share = $Share;
99107
NoDatabaseRestoreCheck = $NoDatabaseRestoreCheck;
100108
DontCheckJobOutcome = $DontCheckJobOutcome }
101109
}
110+
if($Report)
111+
{
112+
$Date = Get-Date -Format ddMMyyyHHmmss
113+
$File = $tempFolder + '\Script_Pester_Report_' + $date
114+
$XML = $File + '.xml'
115+
$HTML = $file + '.html'
116+
Invoke-Pester -Script $Script -OutputFile $xml -OutputFormat NUnitXml
117+
$tempFolder = 'c:\temp'
118+
Push-Location $tempFolder
119+
#download and extract ReportUnit.exe
120+
$url = 'http://relevantcodes.com/Tools/ReportUnit/reportunit-1.2.zip'
121+
$fullPath = Join-Path $tempFolder $url.Split("/")[-1]
122+
$reportunit = $tempFolder + '\reportunit.exe'
123+
if((Test-Path $reportunit) -eq $false)
124+
{
125+
(New-Object Net.WebClient).DownloadFile($url,$fullPath)
126+
Expand-Archive -Path $fullPath -DestinationPath $tempFolder
127+
}
128+
#run reportunit against report.xml and display result in browser
129+
& .\reportunit.exe $XML
130+
ii $HTML
131+
}
132+
else
133+
{
102134
Invoke-Pester -Script $Script
103135
}
136+
}

0 commit comments

Comments
 (0)