Skip to content

Instantly share code, notes, and snippets.

@rasimmers
Created November 7, 2016 22:36
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 rasimmers/53edc563ca5c079397e2dd1795b2815c to your computer and use it in GitHub Desktop.
Save rasimmers/53edc563ca5c079397e2dd1795b2815c to your computer and use it in GitHub Desktop.
Add-Type -AssemblyName System.Xml.Linq
$disks = Get-WMIObject -Class Win32_LogicalDisk -Filter "DriveType = '3'" |
Select DeviceID,
VolumeName,
@{Name="FreeSpaceMB";Expression={[math]::Round($_.Freespace / 1mb)}},
@{Name="SizeMB";Expression={[math]::Round($_.Size / 1mb)}}
# Get the running processes to x(ht)ml
$xml = [System.Xml.Linq.XDocument]::Parse( "$($disks | ConvertTo-Html)" )
#Remove colgroup
($xml.Descendants("{http://www.w3.org/1999/xhtml}colgroup"))| foreach{$_.Remove()}
#Add style to table tags
foreach ($tag in ($xml.Descendants("{http://www.w3.org/1999/xhtml}table"))) {
$tag.SetAttributeValue( "style", "border-collapse: collapse;border: 3px solid black;padding: 5px;")
}
#Add style to th tags
foreach ($tag in ($xml.Descendants("{http://www.w3.org/1999/xhtml}th"))) {
$tag.SetAttributeValue( "style", "border-collapse: collapse;border: 3px solid black;padding: 5px;background-color: lightgray;")
}
#Add style to td tags
foreach ($tag in ($xml.Descendants("{http://www.w3.org/1999/xhtml}td"))) {
$tag.SetAttributeValue( "style", "border-collapse: collapse;border: 3px solid black;padding: 5px;")
}
# Find the index of the column you want to format:
$wsIndex = (($xml.Descendants("{http://www.w3.org/1999/xhtml}th") | Where-Object { $_.Value -eq "FreeSpaceMB" }).NodesBeforeSelf() | Measure-Object ).Count
# Format the column based on whatever rules you have:
switch($xml.Descendants("{http://www.w3.org/1999/xhtml}td") | Where { ($_.NodesBeforeSelf() | Measure-Object).Count -eq $wsIndex } ) {
{ [int]$_.Value -lt 500 } {
if ($tag.Attribute("style")) {
$_.SetAttributeValue( "style", ("background: red; {0}" -f $tag.Attribute("style").Value))
continue
}
} #500
{ [int]$_.Value -lt 30000 } {
if ($tag.Attribute("style")) {
$_.SetAttributeValue( "style", ("background: orange; {0}" -f $tag.Attribute("style").Value))
continue
}
} #30000
{ [int]$_.Value -lt 250000 } {
if ($tag.Attribute("style")) {
$_.SetAttributeValue( "style", ("background: yellow; {0}" -f $tag.Attribute("style").Value))
continue
}
} #250000
}
# Save the html out to a file
$xml.Save("$env:Temp\disks.html")
# Open the thing in your browser to see what we've wrought
ii "$env:Temp\disks.html"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment