Add check-drives.ps1

This commit is contained in:
Markus Fleschutz 2021-12-03 10:12:56 +01:00
parent 9a768c3591
commit 6a7971267c
3 changed files with 44 additions and 4 deletions

View File

@ -97,7 +97,7 @@ Computer, open `name` settings
Computer, check `name`
----------------------
* let the computer check something.
* replace `name` by: "CPU", "date", "DNS", "Earth", "operating system", "ping", "swap space", "time", "time zone", "up-time", "VPN", or "weather".
* replace `name` by: "CPU", "date", "DNS", "drives", "Earth", "operating system", "ping", "swap space", "time", "time zone", "up-time", "VPN", or "weather".
🔊 Audio

39
Scripts/check-drives.ps1 Executable file
View File

@ -0,0 +1,39 @@
<#
.SYNOPSIS
Checks all drives for free space left (20 GB by default)
.DESCRIPTION
This script checks all drives for free space left (20 GB by default).
.PARAMETER MinLevel
Specifies the minimum level in Gigabyte
.EXAMPLE
PS> ./check-drives
Drive C has 172G left (233G total)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz · License: CC0
#>
param([int]$MinLevel = 20) # minimum level in GB
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
[int]$Total = ($Used + $Free)
if ($Free -lt $MinLevel) {
$Reply = "Drive $($Drive.Name) has only $Free GB left to use! ($Used of $Total GB used, minimum is $MinLevel GB)"
} else {
$Reply = "Drive $($Drive.Name) has $($Free)G left ($($Total)G total)"
}
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
}
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
Checks the VPN connection(s)
Checks the VPN connections
.DESCRIPTION
This script checks the VPN connection(s).
This script checks all available VPN connections.
.EXAMPLE
PS> ./check-vpn
.LINK
@ -15,7 +15,8 @@ try {
$Connections = (Get-VPNConnection)
$Reply = ""
foreach($Connection in $Connections) {
$Reply += "VPN connection $($Connection.Name) is $($Connection.ConnectionStatus), "
if ("$Reply" -eq "") { $Reply += "VPN connection " } else { $Reply += ", " }
$Reply += "$($Connection.Name) is $($Connection.ConnectionStatus)"
}
if ("$Reply" -eq "") { $Reply = "No VPN connection available" }