-
-
Save irwins/04e4ff3f5546fa584ce907715c39c996 to your computer and use it in GitHub Desktop.
Get-ADReportUnit.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Author: I. Strachan | |
Version: | |
Version History: | |
Purpose: Get Active Directory Report Unit tests and send notification to Slack | |
#> | |
#region import module and saved credentials/tokens | |
Import-Module PSSlack | |
#Jaap Brassers blog on saving credentials. Saved slack's token as a password | |
#http://www.jaapbrasser.com/quickly-and-securely-storing-your-credentials-powershell/ | |
$savedCreds = Import-CliXml -Path "${env:\userprofile}\Hash.Cred" | |
$token = $savedCreds.'udm-slack'.GetNetworkCredential().Password | |
$exportDate = Get-Date -Format ddMMyyyy | |
#endregion | |
#region Main | |
$pesterADDS = Invoke-Pester .\ps1\dsa\AD.Operations* -OutputFile .\export\adds\ADConfiguration.NUnit.xml -OutputFormat NUnitXml -PassThru | |
#run reportunit against DFSnShares.NUnit.xml and display result in browser | |
& .\tools\ReportUnit\reportunit.exe .\export\adds\ADConfiguration.NUnit.xml | |
Invoke-Item .\export\adds\ADConfiguration.NUnit.html | |
#Export Pester results to xml | |
$pesterADDS | Export-Clixml .\export\adds\PesterResults-ADDS-$($exportDate).xml -Encoding UTF8 | |
#endregion | |
#region Send Slack notification of Pester results | |
$iconEmoji = @{$true = ':white_check_mark:';$false=':red_circle:'}[$pesterADDS.FailedCount -eq 0] | |
$color = @{$true='green';$false='red'}[$pesterADDS.FailedCount -eq 0] | |
#SlackFields | |
$Fields = [PSCustomObject]@{ | |
Total = $pesterADDS.TotalCount | |
Passed = $pesterADDS.PassedCount | |
Failed = $pesterADDS.FailedCount | |
Skipped = $pesterADDS.SkippedCount | |
Pending = $pesterADDS.PendingCount | |
} | New-SlackField -Short | |
$slackAttachments = @{ | |
Color = $([System.Drawing.Color]::$color) | |
PreText = 'Active Directory Pester Results' | |
AuthorName = '@irwins' | |
AuthorIcon = 'https://raw.githubusercontent.com/irwins/PowerShell-scripts/master/wrench.png' | |
Fields = $Fields | |
Fallback = 'Your client is bad' | |
Title = 'Pester counts' | |
TitleLink = 'https://www.youtube.com/watch?v=IAztPZBQrrU' | |
Text = @{$true='Everything passed';$false='Check failed tests'}[$pesterADDS.FailedCount -eq 0] | |
} | |
New-SlackMessageAttachment @slackAttachments | | |
New-SlackMessage -Channel 'powershell' -IconEmoji $iconEmoji -AsUser -Username '@irwins' | | |
Send-SlackMessage -Token $token | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment