Skip to content

Instantly share code, notes, and snippets.

@RamblingCookieMonster
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RamblingCookieMonster/0cff27b3b0df7df89946 to your computer and use it in GitHub Desktop.
Save RamblingCookieMonster/0cff27b3b0df7df89946 to your computer and use it in GitHub Desktop.
PSO.PSExcelFormatRed
# Install PSExcel
# https://github.com/RamblingCookieMonster/PSExcel#instructions
Import-Module PSExcel
$File = "C:\SGroupMemberDetails.xlsx"
#Some fake information, PS2 compatible
$Output = 1..10 | ForEach-Object {
New-Object -TypeName PSObject -Property @{
ComputerName = "Computer$_"
Admins = "Some", "list", "of", "admins" -join ", "
Connected = $($True, $False | Get-Random )
}
} | Select-Object -Property ComputerName, Admins, Connected
#Output the initial data
$Output | Export-XLSX -Path $File -AutoFit
#Find cells that are false. Verify that they are in col 3 (connected)
$FailedRows = Search-CellValue -Path $File -FilterScript {$_ -eq $False} |
Where-Object {$_.Column -eq 3} |
Select -ExpandProperty Row
#Scaffolding for Format-Cell. I know. It's a pain.
$Excel = New-Excel -Path $File
$WorkSheet = $Excel | Get-Worksheet
#Make the header bold, make the failed servers red!
$Worksheet | Format-Cell -Header -Bold $True -Border Bottom
foreach($Row in $FailedRows)
{
$Worksheet | Format-Cell -StartRow $Row -EndRow $Row -BackgroundColor LightSalmon -FillStyle Solid
}
$Excel | Close-Excel -Save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment