Skip to content

Commit 85471d7

Browse files
committed
Updated output to be much shorter so "everything" can be seen at one glance in the Checks view.
1 parent 503c48e commit 85471d7

5 files changed

Lines changed: 259 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<#
2+
.Synopsis
3+
Checks the battery full charge capacity VS the design capacity
4+
.DESCRIPTION
5+
This was written specifically for use as a "Script Check" in mind, where it the output is deliberaly light unless a warning or error condition is found that needs more investigation.
6+
7+
If the total full charge capacity is less than the minimum capacity amount, an error is returned.
8+
#>
9+
10+
[CmdletBinding()]
11+
param(
12+
[Parameter(Mandatory = $false)]
13+
[int]#The minimum battery full charge capacity (as a percentage of design capacity by default). Defaults to 85 percent.
14+
$minimumBatteryCapacity = 85,
15+
16+
[Parameter(Mandatory = $false)]
17+
[switch]#Set the check condition to absolute mWh values instead of a percentage
18+
$absoluteValues
19+
)
20+
21+
try{
22+
$searcher = New-Object System.Management.ManagementObjectSearcher("root\wmi","SELECT * FROM BatteryStaticData")
23+
$batteryStatic = $searcher.Get()
24+
#CIM approach threw errors when Get-WMIObject did not - WMI approach is not available in PSv7, so took .NET approach
25+
$batteryCharge = Get-CimInstance -Namespace "root\wmi" -ClassName "BatteryFullChargedCapacity" -ErrorAction Stop
26+
} catch {
27+
Write-Output "No battery detected"
28+
exit 0
29+
}
30+
31+
if (-not $batteryStatic -or -not $batteryCharge) {
32+
Write-Output "No battery detected"
33+
exit 0
34+
}
35+
36+
$chargeCapacity = $batteryCharge.FullChargedCapacity
37+
$designCapacity = $batteryStatic.DesignedCapacity
38+
39+
$available = [math]::Round(($chargeCapacity / $designCapacity) * 100,2)
40+
$label = "%"
41+
if ($absoluteValues) {
42+
$available = $chargeCapacity
43+
$label = "mWh"
44+
}
45+
46+
"Full charge capacity $available$label of $designCapacity mWh."
47+
48+
If($available -le $minimumBatteryCapacity){ Exit 1 }
49+
Exit 0
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<#
2+
.Synopsis
3+
Checks Uptime of the computer
4+
.DESCRIPTION
5+
This was written specifically for use as a "Script Check" in mind, where it the output is deliberaly light unless a warning or error condition is found that needs more investigation.
6+
7+
If the totalhours of uptime of the computer is greater than or equal to the warning limit, an error is returned.
8+
#>
9+
10+
[cmdletbinding()]
11+
Param(
12+
[Parameter(Mandatory = $false)]
13+
[int]#Warn if the uptime total hours is over this limit. Defaults to 2.5 days.
14+
$maximumUptimeHoursWarningLimit = 60
15+
)
16+
17+
$uptime = (get-Date) - (Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty LastBootUpTime)
18+
#v7 introduces Get-Uptime, but using WMI is backwards compatiable with v5
19+
20+
$hiberbootEnabled = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power' -Name 'HiberbootEnabled' -ErrorAction Stop).HiberbootEnabled
21+
[bool]$FastStartupEnabled = ($hiberbootEnabled -eq 1)
22+
23+
"CPU Uptime $([math]::Round($uptime.TotalHours,2)) hours. Fast Startup enabled: $FastStartupEnabled"
24+
25+
If($uptime.TotalHours -ge $maximumUptimeHoursWarningLimit){ Exit 1 }
26+
Exit 0
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<#
2+
.Synopsis
3+
Outputs Drive Health
4+
.DESCRIPTION
5+
This was written specifically for use as a "Script Check" in mind, where it the output is deliberaly light unless a warning or error condition is found that needs more investigation.
6+
7+
Uses the Windows Storage Reliabilty Counters first (the information behind Settings - Storage - Disks & Volumes - %DiskID% - Drive health) to report on drive health.
8+
9+
Will exit if running on a virtual machine.
10+
11+
.NOTES
12+
Learing taken from "Win_Disk_SMART2.ps1" by nullzilla, and modified by: redanthrax
13+
#>
14+
15+
# Requires -Version 5.0
16+
# Requires -RunAsAdministrator
17+
[cmdletbinding()]
18+
Param(
19+
[Parameter(Mandatory = $false)]
20+
[int]#Warn if the temperature (in degrees C) is over this limit
21+
$TemperatureWarningLimit = 60,
22+
23+
[Parameter(Mandatory = $false)]
24+
[int]#Warn if the "wear" of the drive (as a percentage) is above this
25+
$maximumWearAllowance = 20
26+
)
27+
28+
BEGIN {
29+
# If this is a virtual machine, we don't need to continue
30+
$Computer = Get-CimInstance -ClassName 'Win32_ComputerSystem'
31+
if ($Computer.Model -like 'Virtual*') {
32+
exit
33+
}
34+
}
35+
36+
PROCESS {
37+
Try{
38+
#Using Windows Storage Reliabilty Counters first (the information behind Settings - Storage - Disks & Volumes - %DiskID% - Drive health)
39+
$physicalDisks = Get-PhysicalDisk -ErrorAction Stop
40+
foreach ($disk in $physicalDisks) {
41+
$reliabilityCounter = $null
42+
try {
43+
$reliabilityCounter = $disk | Get-StorageReliabilityCounter -ErrorAction Stop
44+
}
45+
catch {
46+
Write-Error "No Storage Reliability Counter for '$($disk.FriendlyName)'. This usually means the driver/controller isn't exposing it."
47+
}
48+
$driveLetters = (get-disk -FriendlyName $Disk.FriendlyName | Get-Partition | Where-Object -FilterScript {$_.DriveLetter} | Select-Object -Expand DriveLetter) -join ", "
49+
50+
<#
51+
DriveLetters = $driveLetters
52+
HealthStatus = $disk.HealthStatus
53+
FriendlyName = $disk.FriendlyName
54+
SerialNumber = $disk.SerialNumber
55+
BusType = $disk.BusType
56+
OperationalStatus = ($disk.OperationalStatus -join ", ")
57+
Temperature = $reliabilityCounter.Temperature
58+
Wear = $reliabilityCounter.Wear
59+
ReadErrorsTotal = $reliabilityCounter.ReadErrorsTotal
60+
WriteErrorsTotal = $reliabilityCounter.WriteErrorsTotal
61+
ReallocatedSectors = $reliabilityCounter.ReallocatedSectors
62+
PowerOnHours = $reliabilityCounter.PowerOnHours
63+
#>
64+
If(
65+
$disk.HealthStatus.ToLower() -ne "healthy" -or
66+
($disk.OperationalStatus | Where-Object -FilterScript { $_.ToLower() -ne "ok" }) -or
67+
$reliabilityCounter.Wear -gt $maximumWearAllowance -or
68+
$reliabilityCounter.Temperature -gt $TemperatureWarningLimit
69+
){
70+
"Disk issue: $DriveLetters $($disk.HealthStatus) Status:$(($disk.OperationalStatus -join ", ")) $($reliabilityCounter.Temperature)*C $($reliabilityCounter.Wear)% wear"
71+
Write-Error -Message "Disk issues need investigating"
72+
} else {
73+
"$DriveLetters $($disk.HealthStatus) Status:$(($disk.OperationalStatus -join ", ")) $($reliabilityCounter.Temperature)*C $($reliabilityCounter.Wear)% wear"
74+
}
75+
}
76+
} catch {
77+
Write-Error -Message "Get-PhysicalDisk failed. This can happen on older OS builds or restricted environments."
78+
}
79+
}
80+
81+
END{
82+
if ($error) { Exit 1 }
83+
Exit 0
84+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<#
2+
.Synopsis
3+
Checks all FileSystem drives for an amount of space specified. Fails if less than space specified.
4+
.DESCRIPTION
5+
Long description
6+
Checks all FileSystem drives for an amount of space specified (amount is converted to Gigabytes).
7+
.EXAMPLE
8+
Confirm-DiskSpaceAvailable -Size 10
9+
.EXAMPLE
10+
Confirm-DiskSpaceAvailable -Size 10 -Percent
11+
.NOTES
12+
Version: 1.0
13+
Author: redanthrax
14+
Creation Date: 2022-04-05
15+
Updated: Owen Conti 2025-12-12
16+
#>
17+
18+
Param(
19+
[Parameter(Mandatory = $false)]
20+
[int]#The minimum amount of GB that should be available
21+
$Size = 25,
22+
23+
[Parameter(Mandatory = $false)]
24+
[switch]#Switches the Size to be a percentage instead of GB
25+
$Percent
26+
)
27+
28+
Begin {}
29+
30+
Process {
31+
Try {
32+
$errors = 0
33+
$drives = Get-PSDrive | Where-Object { $_.Provider.Name -eq "FileSystem" -and $_.Used -gt 0 -and $_.Name.ToLower() -ne "temp" }
34+
foreach ($drive in $drives) {
35+
[string]$label = "GB"
36+
[double]$available = 0
37+
if ($Percent) {
38+
#Percent flag is set
39+
#Calculate percent of free space left on drive
40+
$available = [math]::Round(($drive.Free / ($drive.Free + $drive.Used)) * 100,2)
41+
$label = "%"
42+
}
43+
else {
44+
$available = [math]::Round($drive.Free / 1Gb, 2)
45+
}
46+
47+
"$($drive.Name) $available $label space remaining."
48+
49+
if ($Size -gt $available) {
50+
$errors += 1
51+
}
52+
}
53+
}
54+
55+
Catch {
56+
"ERROR: ${$_.Exception}"
57+
Exit 1
58+
}
59+
}
60+
61+
End {
62+
if ($errors -gt 0) { Exit 1 }
63+
Exit 0
64+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<#
2+
.Synopsis
3+
Checks the available amount of RAM on a computer
4+
.DESCRIPTION
5+
This was written specifically for use as a "Script Check" in mind, where it the output is deliberaly light unless a warning or error condition is found that needs more investigation.
6+
7+
If the total available (free) amount of RAM is less than the warning limit, an error is returned.
8+
9+
#>
10+
11+
[cmdletbinding()]
12+
Param(
13+
[Parameter(Mandatory = $false)]
14+
[double]#Warn if the amount of available RAM (defaults to GB) is below this limit. Defaults to 1 GB.
15+
$minimumAvailableRAM = 0.75,
16+
17+
[Parameter(Mandatory = $false)]
18+
[switch]#Use percentage instead of absolute GB values
19+
$percent
20+
)
21+
22+
$os = Get-CimInstance -ClassName Win32_OperatingSystem
23+
24+
$available = [math]::Round(($os.FreePhysicalMemory * 1KB) / 1GB, 2)
25+
$label = "GB"
26+
if ($Percent) {
27+
#Percent flag is set
28+
#Calculate percent of free available RAM
29+
$available = [math]::Round(($os.FreePhysicalMemory / $os.TotalVisibleMemorySize) * 100, 1)
30+
$label = "%"
31+
}
32+
33+
"$available $label RAM available."
34+
35+
If($minimumAvailableRAM -gt $available){ Exit 1 }
36+
Exit 0

0 commit comments

Comments
 (0)