mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-26 14:26:10 +01:00
Update check-drives.ps1 and check-swap-space.ps1
This commit is contained in:
parent
fbdddbabe8
commit
ebd663e34e
@ -2,7 +2,7 @@
|
||||
.SYNOPSIS
|
||||
Checks the free space of all drives
|
||||
.DESCRIPTION
|
||||
This PowerShell script checks all drives for free space left (20 GB by default).
|
||||
This PowerShell script checks all drives for free space left (10 GB by default).
|
||||
.PARAMETER MinLevel
|
||||
Specifies the minimum warning level (10 GB by default)
|
||||
.EXAMPLE
|
||||
@ -18,17 +18,18 @@ param([int]$MinLevel = 10) # 10 GB minimum
|
||||
try {
|
||||
$Drives = Get-PSDrive -PSProvider FileSystem
|
||||
foreach($Drive in $Drives) {
|
||||
$DriveDetails = (Get-PSDrive $Drive.Name)
|
||||
[int]$Free = (($DriveDetails.Free / 1024) / 1024) / 1024
|
||||
[int]$Used = (($DriveDetails.Used / 1024) / 1024) / 1024
|
||||
$ID = $Drive.Name
|
||||
$Details = (Get-PSDrive $ID)
|
||||
[int]$Free = $Details.Free / 1GB
|
||||
[int]$Used = $Details.Used / 1GB
|
||||
[int]$Total = ($Used + $Free)
|
||||
|
||||
if ($Total -eq "0") {
|
||||
"✅ Drive $($Drive.Name) is empty."
|
||||
"✅ Drive $ID is empty."
|
||||
} elseif ($Free -lt $MinLevel) {
|
||||
"⚠️ Drive $($Drive.Name) has only $Free GB left to use! $Used of $Total GB is in use."
|
||||
"⚠️ Drive $ID has only $Free GB of $Total GB left to use!"
|
||||
} else {
|
||||
"✅ Drive $($Drive.Name) has $($Free) GB left, $($Total) GB total."
|
||||
"✅ Drive $ID has $Free GB of $Total GB left."
|
||||
}
|
||||
}
|
||||
exit 0 # success
|
||||
|
@ -7,7 +7,7 @@
|
||||
Specifies the minimum level (10 GB by default)
|
||||
.EXAMPLE
|
||||
PS> ./check-swap-space
|
||||
✅ Swap space has 1826 GB left, 1856 GB total.
|
||||
✅ Swap space has 1826 GB of 1856 GB left.
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -23,7 +23,7 @@ try {
|
||||
[int]$Used = $Result.substring(20,13)
|
||||
[int]$Free = $Result.substring(32,11)
|
||||
} else {
|
||||
$Items = get-wmiobject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost
|
||||
$Items = Get-WmiObject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost
|
||||
foreach ($Item in $Items) {
|
||||
[int]$Total = $Item.AllocatedBaseSize
|
||||
[int]$Used = $Item.CurrentUsage
|
||||
@ -34,9 +34,9 @@ try {
|
||||
if ($Total -eq "0") {
|
||||
"⚠️ No swap space."
|
||||
} elseif ($Free -lt $MinLevel) {
|
||||
"⚠️ Swap space has only $Free GB left, $Total GB total!"
|
||||
"⚠️ Swap space has only $Free GB of $Total GB left to use!"
|
||||
} else {
|
||||
"✅ Swap space has $Free GB left, $Total GB total."
|
||||
"✅ Swap space has $Free GB of $Total GB left."
|
||||
}
|
||||
exit 0 # success
|
||||
} catch {
|
||||
|
Loading…
Reference in New Issue
Block a user