mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-16 17:51:28 +01:00
Add check-drives.ps1
This commit is contained in:
parent
9a768c3591
commit
6a7971267c
@ -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
39
Scripts/check-drives.ps1
Executable 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
|
||||
}
|
@ -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" }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user