Added check-drive-space.ps1

This commit is contained in:
Markus Fleschutz 2021-02-26 11:06:01 +01:00
parent ac2f03adfe
commit a6e05aa167
4 changed files with 31 additions and 2 deletions

View File

@ -1,5 +1,6 @@
Script,Description
add-firewall-rules.ps1, adds firewall rules to the given executables (requires admin rights)
check-drive-space.ps1, checks the given drive for free space left
check-ipv4-address.ps1, checks the given IPv4 address for validity
check-ipv6-address.ps1, checks the given IPv6 address for validity
check-mac-address.ps1, checks the given MAC address for validity

1 Script Description
2 add-firewall-rules.ps1 adds firewall rules to the given executables (requires admin rights)
3 check-drive-space.ps1 checks the given drive for free space left
4 check-ipv4-address.ps1 checks the given IPv4 address for validity
5 check-ipv6-address.ps1 checks the given IPv6 address for validity
6 check-mac-address.ps1 checks the given MAC address for validity

View File

@ -30,6 +30,7 @@ Scripts for Audio & Voice 🔊
Scripts for Computer Management ⚙️
---------------------------------
* [add-firewall-rules.ps1](Scripts/add-firewall-rules.ps1) - adds firewall rules for the given executables (requires admin rights)
* [check-drive-space.ps1](Scripts/check-drive-space.ps1) - checks the given drive for free space left
* [enable-crash-dumps.ps1](Scripts/enable-crash-dumps.ps1) - enables the writing of crash dumps
* [hibernate.ps1](Scripts/hibernate.ps1) - enables hibernate mode for the local computer (requires admin rights)
* [list-network-shares.ps1](Scripts/list-network-shares.ps1) - lists the network shares of the local computer

29
Scripts/check-drive-space.ps1 Executable file
View File

@ -0,0 +1,29 @@
#!/bin/powershell
<#
.SYNTAX ./check-drive-space.ps1 [<drive>] [<warning-level>]
.DESCRIPTION checks the given drive for free space left
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Drive = "", $WarningLevel = 50) #limit in gb
if ($Drive -eq "" ) {
$Drive = read-host "Enter drive to check"
}
try {
$FreeSpace = (get-psdrive $Drive).free
[int]$FreeSpace = (($FreeSpace / 1024) / 1024) / 1024
if ($FreeSpace -lt $WarningLevel) {
write-warning "Drive $Drive has only $FreeSpace GB free space left! (warning level is < $WarningLevel GB)"
exit 1
} else {
write-host -foregroundColor green "OK - drive $Drive has $FreeSpace GB free space left (warning level is < $WarningLevel GB)"
exit 0
}
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -1,5 +1,3 @@
write-host -foregroundColor green "Welcome to PowerShell $($PSVersionTable.PSVersion)"
#function prompt {$null} # PS>
#function prompt { "$ " } # $