mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-23 18:38:19 +02:00
Updated check-uptime.ps1
This commit is contained in:
parent
306cd65327
commit
1e6d5ac3a5
@ -12,7 +12,7 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function TimeSpan2String([TimeSpan]$uptime)
|
function TimeSpanAsString([TimeSpan]$uptime)
|
||||||
{
|
{
|
||||||
[int]$days = $uptime.Days
|
[int]$days = $uptime.Days
|
||||||
[int]$hours = $days * 24 + $uptime.Hours
|
[int]$hours = $days * 24 + $uptime.Hours
|
||||||
@ -26,16 +26,15 @@ function TimeSpan2String([TimeSpan]$uptime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$hostname = $(hostname)
|
|
||||||
if ($IsLinux) {
|
|
||||||
$uptime = (Get-Uptime)
|
|
||||||
Write-Host "✅ $hostname is up for $(TimeSpan2String $uptime)"
|
|
||||||
} else {
|
|
||||||
[system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US"
|
[system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US"
|
||||||
|
if ($IsLinux) {
|
||||||
|
$lastBootTime = (Get-Uptime -since)
|
||||||
|
$uptime = (Get-Uptime)
|
||||||
|
} else {
|
||||||
$lastBootTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
|
$lastBootTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
|
||||||
$uptime = New-TimeSpan -Start $lastBootTime -End (Get-Date)
|
$uptime = New-TimeSpan -Start $lastBootTime -End (Get-Date)
|
||||||
Write-Host "✅ $hostname is up for $(TimeSpan2String $uptime) since $($lastBootTime.ToShortDateString())"
|
|
||||||
}
|
}
|
||||||
|
Write-Host "✅ $(hostname) is up for $(TimeSpanAsString $uptime) since $($lastBootTime.ToShortDateString())"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user