mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-17 08:01:31 +02:00
Updated the manuals
This commit is contained in:
@ -24,14 +24,14 @@ Script Content
|
||||
This PowerShell script queries the computer's uptime (time between now and last boot up time) and prints it.
|
||||
.EXAMPLE
|
||||
PS> ./check-uptime.ps1
|
||||
✅ Up for 2 days, 20 hours, 10 minutes
|
||||
✅ OfficePC is up for 13 days since 1/25/2024
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
function TimeSpan2String([TimeSpan]$uptime)
|
||||
function TimeSpanAsString([TimeSpan]$uptime)
|
||||
{
|
||||
[int]$days = $uptime.Days
|
||||
[int]$hours = $days * 24 + $uptime.Hours
|
||||
@ -45,15 +45,15 @@ function TimeSpan2String([TimeSpan]$uptime)
|
||||
}
|
||||
|
||||
try {
|
||||
[system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US"
|
||||
if ($IsLinux) {
|
||||
$lastBootTime = (Get-Uptime -since)
|
||||
$uptime = (Get-Uptime)
|
||||
Write-Host "✅ Up for $(TimeSpan2String $uptime)"
|
||||
} else {
|
||||
[system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US"
|
||||
$lastBootTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
|
||||
$uptime = New-TimeSpan -Start $lastBootTime -End (Get-Date)
|
||||
Write-Host "✅ Up for $(TimeSpan2String $uptime) since $($lastBootTime.ToShortDateString())"
|
||||
}
|
||||
Write-Host "✅ $(hostname) is up for $(TimeSpanAsString $uptime) since $($lastBootTime.ToShortDateString())"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
@ -61,4 +61,4 @@ try {
|
||||
}
|
||||
```
|
||||
|
||||
*(generated by convert-ps2md.ps1 using the comment-based help of check-uptime.ps1 as of 01/25/2024 13:58:37)*
|
||||
*(generated by convert-ps2md.ps1 using the comment-based help of check-uptime.ps1 as of 03/27/2024 17:36:25)*
|
||||
|
Reference in New Issue
Block a user