mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-25 13:36:39 +01:00
Update check-drive-space.ps1 and check-swap-space.ps1
This commit is contained in:
parent
73f0adffe6
commit
17d4943291
@ -1,12 +1,12 @@
|
||||
#!/bin/powershell
|
||||
<#
|
||||
.SYNTAX ./check-drive-space.ps1 [<drive>] [<warning-level>]
|
||||
.SYNTAX ./check-drive-space.ps1 [<drive>] [<min-level>]
|
||||
.DESCRIPTION checks the given drive for free space left
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Drive = "", [int]$WarningLevel = 50) # warning level in GB
|
||||
param($Drive = "", [int]$MinLevel = 50) # minimum level in GB
|
||||
|
||||
if ($Drive -eq "" ) {
|
||||
$Drive = read-host "Enter drive to check"
|
||||
@ -16,11 +16,11 @@ try {
|
||||
$FreeSpace = (get-psdrive $Drive)
|
||||
[int]$FreeSpace = (($FreeSpace.free / 1024) / 1024) / 1024
|
||||
|
||||
if ($FreeSpace -lt $WarningLevel) {
|
||||
write-warning "Drive $Drive has only $FreeSpace GB free space left! (warning level is < $WarningLevel GB)"
|
||||
if ($FreeSpace -lt $MinLevel) {
|
||||
write-warning "Drive $Drive has only $FreeSpace GB free space left! (minimum is $MinLevel GB)"
|
||||
exit 1
|
||||
}
|
||||
write-host -foregroundColor green "OK - drive $Drive has $FreeSpace GB free space left (warning level is < $WarningLevel GB)"
|
||||
write-host -foregroundColor green "OK - drive $Drive has $FreeSpace GB free space left (minimum is $MinLevel GB)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -1,21 +1,26 @@
|
||||
#!/bin/powershell
|
||||
<#
|
||||
.SYNTAX ./check-swap-space.ps1 [<warning-level>]
|
||||
.DESCRIPTION checks the swap space
|
||||
.SYNTAX ./check-swap-space.ps1 [<min-level>]
|
||||
.DESCRIPTION checks the free swap space
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param([int]$WarningLevel = 50) # warning level in GB
|
||||
param([int]$MinLevel = 50) # minimum level in GB
|
||||
|
||||
try {
|
||||
$colItems = get-wmiobject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost
|
||||
$Items = get-wmiobject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost
|
||||
|
||||
foreach ($objItem in $colItems) {
|
||||
$allocate = $objItem.AllocatedBaseSize
|
||||
$current = $objItem.CurrentUsage
|
||||
foreach ($Item in $Items) {
|
||||
$Total = $Item.AllocatedBaseSize
|
||||
$Current = $Item.CurrentUsage
|
||||
$FreeSpace = ($Total - $Current)
|
||||
}
|
||||
write-host ($allocate - $current)
|
||||
if ($FreeSpace -lt $MinLevel) {
|
||||
write-warning "Swap space has only $FreeSpace GB left to use! ($Current GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
exit 1
|
||||
}
|
||||
write-host -foregroundColor green "OK - swap space has $FreeSpace GB left to use ($Current GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
Loading…
Reference in New Issue
Block a user