Created
July 11, 2016 22:08
-
-
Save rasimmers/4d57355cb14b21cfa66afa2ca3eb1798 to your computer and use it in GitHub Desktop.
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
function Out-MyReport { | |
[CmdLetBinding()] | |
param( | |
$obj | |
) | |
begin{} | |
process{ | |
$stringBuilder = New-Object System.Text.StringBuilder | |
$null = $stringBuilder.Append("<table>`r`n") | |
#My Distribution groups had spaces in them and Group-Object did not like it, so I just created another column to group with no spaces | |
$obj = $obj | Select *, @{Name="CompareDG";Expression={$_.DistributionGroup -replace " ", ""}} | |
$groupedDG = $($obj | Group-Object -Property CompareDG) | |
foreach ($group in $groupedDG) { | |
Write-Verbose ("{0} ({1})" -f $group.Name, $group.Count ) | |
$null = $stringBuilder.Append("<tr>`r`n") | |
$null = $stringBuilder.Append(("<td>{0} ({1})</td>" -f $group.Group[0].DistributionGroup, $group.Count)) | |
$null = $stringBuilder.Append("<td><table class='users'>`r`n") | |
foreach ($user in $group.Group) { | |
$null = $stringBuilder.Append("<tr>`r`n") | |
$null = $stringBuilder.Append("<td class='users'>{0}</td>" -f $user.Name) | |
$null = $stringBuilder.Append("`r`n</tr>") | |
} | |
$null = $stringBuilder.Append("</table>`r`n") | |
$null = $stringBuilder.Append("`r`n</tr>`r`n") | |
} | |
$null = $stringBuilder.Append("</td></table>") | |
} | |
end{ | |
$htmlReport = @" | |
<html><head><title>My Report</title> | |
<style type="text/css"> | |
<!-- | |
body { | |
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; | |
color: black; | |
font-size: 12px; | |
} | |
table{ | |
border-collapse: collapse; | |
border-width: 1px; | |
border-style: solid; | |
border-color: black; | |
font: 10pt Verdana, Geneva, Arial, Helvetica, sans-serif; | |
} | |
table td{ | |
border-collapse: collapse; | |
border-width: 1px; | |
border-style: solid; | |
border-color: black; | |
text-align: center; | |
} | |
.users { | |
border:none; | |
text-align: center; | |
} | |
</style> | |
</head> | |
<body> | |
$($stringBuilder.ToString()) | |
</body> | |
</html> | |
"@ | |
Write-Verbose $stringBuilder.ToString() | |
$htmlReport | |
} | |
} | |
$htmlReport = Out-MyReport -obj $results | |
$htmlReport | Out-File "C:\Users\Rob\Desktop\report.html" | |
ii "C:\Users\Rob\Desktop\report.html" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment