mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-15 22:48:17 +02:00
Add check-health.ps1
This commit is contained in:
parent
296886b362
commit
85d3137b14
@ -1,6 +1,8 @@
|
||||
Script,Description
|
||||
add-firewall-rules.ps1, adds firewall rules to the given executables (requires admin rights)
|
||||
check-dns-resolution.ps1, checks the DNS resolution with frequently used domain names
|
||||
check-drive-space.ps1, checks the given drive for free space left
|
||||
check-health.ps1, checks the system health
|
||||
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
|
||||
@ -127,7 +129,6 @@ switch-branch.ps1, switches the branch in the current/given Git repository (incl
|
||||
switch-shelly1.ps1, switches a Shelly1 device in the local network
|
||||
take-screenshot.ps1, takes a single screenshot
|
||||
take-screenshots.ps1, takes multiple screenshots
|
||||
train-dns-cache.ps1, trains the DNS cache with frequently used domain names
|
||||
translate-text.ps1, translates the given text into other languages
|
||||
turn-volume-up.ps1, turns the audio volume up (+10% by default)
|
||||
turn-volume-down.ps1, turns the audio volume down (-10% by default)
|
||||
|
|
@ -30,7 +30,9 @@ Collection of PowerShell Scripts
|
||||
⚙️ Scripts for Computer Management
|
||||
---------------------------------
|
||||
* [add-firewall-rules.ps1](Scripts/add-firewall-rules.ps1) - adds firewall rules for the given executables (requires admin rights)
|
||||
* [check-dns-resolution.ps1](Scripts/check-dns-resolution.ps1) - checks the DNS resolution with frequently used domain names
|
||||
* [check-drive-space.ps1](Scripts/check-drive-space.ps1) - checks the given drive for free space left
|
||||
* [check-health.ps1](Scripts/check-health.ps1) - checks the system health
|
||||
* [check-swap-space.ps1](Scripts/check-swap-space.ps1) - checks the swap space for free space left
|
||||
* [check-windows-system-files.ps1](Scripts/check-windows-system-files.ps1) - checks the validity of the Windows system files (requires admin rights)
|
||||
* [enable-crash-dumps.ps1](Scripts/enable-crash-dumps.ps1) - enables the writing of crash dumps
|
||||
@ -158,7 +160,6 @@ Collection of PowerShell Scripts
|
||||
* [simulate-matrix.ps1](Scripts/simulate-matrix.ps1) - simulates the Matrix (fun)
|
||||
* [simulate-presence.ps1](Scripts/simulate-presence.ps1) - simulates the human presence against burglars
|
||||
* [switch-shelly1.ps1](Scripts/switch-shelly1.ps1) - switches a Shelly1 device in the local network
|
||||
* [train-dns-cache.ps1](Scripts/train-dns-cache.ps1) - trains the DNS cache with frequently used domain names
|
||||
* [translate-text.ps1](Scripts/translate-text.ps1) - translates the given text into other languages
|
||||
* [weather.ps1](Scripts/weather.ps1) - prints the current weather forecast
|
||||
* [weather-alert.ps1](Scripts/weather-alert.ps1) - checks the current weather for critical values
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/powershell
|
||||
<#
|
||||
.SYNTAX ./train-dns-cache.ps1
|
||||
.DESCRIPTION trains the DNS cache with frequently used domain names
|
||||
.SYNTAX ./check-dns-resolution.ps1
|
||||
.DESCRIPTION checks the DNS resolution with frequently used domain names
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
@ -18,14 +18,14 @@ try {
|
||||
|
||||
foreach($Row in $Table) {
|
||||
$Domain = $Row.Domain
|
||||
write-progress "Training DNS cache with $Domain..."
|
||||
write-progress "Resolving $Domain..."
|
||||
$Ignore = nslookup $Domain
|
||||
}
|
||||
|
||||
$Count = $Table.Length
|
||||
$StopTime = Get-Date
|
||||
$TimeInterval = New-Timespan -start $StartTime -end $StopTime
|
||||
write-host -foregroundColor green "Done - DNS cache trained with $Count domain names in $TimeInterval seconds"
|
||||
write-host -foregroundColor green "OK - resolved $Count domain names in $TimeInterval seconds"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
@ -14,15 +14,15 @@ if ($Drive -eq "" ) {
|
||||
|
||||
try {
|
||||
$DriveDetails = (get-psdrive $Drive)
|
||||
[int]$FreeSpace = (($DriveDetails.Free / 1024) / 1024) / 1024
|
||||
[int]$InUse = (($DriveDetails.Used / 1024) / 1024) / 1024
|
||||
[int]$Total = ($InUse + $FreeSpace)
|
||||
[int]$Free = (($DriveDetails.Free / 1024) / 1024) / 1024
|
||||
[int]$Used = (($DriveDetails.Used / 1024) / 1024) / 1024
|
||||
[int]$Total = ($Used + $Free)
|
||||
|
||||
if ($FreeSpace -lt $MinLevel) {
|
||||
write-warning "Drive $Drive has only $FreeSpace GB left to use! ($InUse GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
if ($Free -lt $MinLevel) {
|
||||
write-warning "Drive $Drive has only $Free GB left to use! ($Used GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
exit 1
|
||||
}
|
||||
write-host -foregroundColor green "OK - drive $Drive has $FreeSpace GB left to use ($InUse GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
write-host -foregroundColor green "OK - $Free GB free at drive $Drive ($Used GB used out of $Total GB, $MinLevel GB is minimum)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
36
Scripts/check-health.ps1
Executable file
36
Scripts/check-health.ps1
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/powershell
|
||||
<#
|
||||
.SYNTAX ./check-health.ps1
|
||||
.DESCRIPTION checks the system health
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
$Hostname = $(hostname)
|
||||
"Checking health of $Hostname ..."
|
||||
|
||||
& check-swap-space.ps1
|
||||
if ($lastExitCode -ne "0") { throw "check-swap-space.ps1 failed" }
|
||||
|
||||
if ($IsLinux) {
|
||||
& check-drive-space.ps1 /
|
||||
} else {
|
||||
& check-drive-space.ps1 C
|
||||
}
|
||||
if ($lastExitCode -ne "0") { throw "check-drive-space.ps1 failed" }
|
||||
|
||||
if (-not($IsLinux)) {
|
||||
& check-windows-system-files.ps1
|
||||
if ($lastExitCode -ne "0") { throw "check-windows-system-files.ps1 failed" }
|
||||
}
|
||||
|
||||
& check-dns-resolution.ps1
|
||||
if ($lastExitCode -ne "0") { throw "check-dns-resolution.ps1 failed" }
|
||||
|
||||
write-host -foregroundColor green "OK - $Hostname is healthy"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user