From a6e05aa1674de11e7b97cc53abcafb2e110c54e7 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Fri, 26 Feb 2021 11:06:01 +0100 Subject: [PATCH] Added check-drive-space.ps1 --- Data/scripts.csv | 1 + README.md | 1 + Scripts/check-drive-space.ps1 | 29 +++++++++++++++++++++++++++++ Scripts/my-profile.ps1 | 2 -- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 Scripts/check-drive-space.ps1 diff --git a/Data/scripts.csv b/Data/scripts.csv index ecaa2983..da5fd6cb 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -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 diff --git a/README.md b/README.md index d9aba8b6..000c0775 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Scripts/check-drive-space.ps1 b/Scripts/check-drive-space.ps1 new file mode 100755 index 00000000..24bff4a3 --- /dev/null +++ b/Scripts/check-drive-space.ps1 @@ -0,0 +1,29 @@ +#!/bin/powershell +<# +.SYNTAX ./check-drive-space.ps1 [] [] +.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 +} diff --git a/Scripts/my-profile.ps1 b/Scripts/my-profile.ps1 index bace4f48..714cbfe9 100644 --- a/Scripts/my-profile.ps1 +++ b/Scripts/my-profile.ps1 @@ -1,5 +1,3 @@ -write-host -foregroundColor green "Welcome to PowerShell $($PSVersionTable.PSVersion)" - #function prompt {$null} # PS> #function prompt { "$ " } # $