Merge branch 'main' of github.com:fleschutz/PowerShell

This commit is contained in:
Markus Fleschutz 2024-12-11 18:54:33 +01:00
commit 7069c2c31b
6 changed files with 40 additions and 40 deletions

View File

@ -441,6 +441,7 @@ RSC,Runway Surface Condition
RSI,Remote Status Indicator RSI,Remote Status Indicator
RSO,Range Safety Officer RSO,Range Safety Officer
RSRS,Reduced Same Runway Separation RSRS,Reduced Same Runway Separation
RSU,Runway Supervisory Unit
RTAF,Royal Thai Air Force RTAF,Royal Thai Air Force
RTCA,Radio Technical Commission for Aeronautics RTCA,Radio Technical Commission for Aeronautics
RTF,Radio Telephony RTF,Radio Telephony
@ -548,6 +549,7 @@ TRA,Temporary Reserved Area
TRACON,Terminal Radar Approach Control TRACON,Terminal Radar Approach Control
TRH,Thrust Reduction Height TRH,Thrust Reduction Height
TSA,Temporary Segregated Area TSA,Temporary Segregated Area
TSAT,Target Startup Approval Time
TSO,Technical Standard Order TSO,Technical Standard Order
TSTC,Texas State Technical College TSTC,Texas State Technical College
TT,True Track TT,True Track

Can't render this file because it has a wrong number of fields in line 139.

View File

@ -7,7 +7,8 @@
Specifies the folder name of the Git repository Specifies the folder name of the Git repository
.EXAMPLE .EXAMPLE
PS> ./cd-repo.ps1 rust PS> ./cd-repo.ps1 rust
📂C:\Repos\rust · on branch: ## main ... origin/main 📂C:\Repos\rust
🌿on branch: ## main ... origin/main
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -38,7 +39,7 @@ try {
$path = Resolve-Path "$path" $path = Resolve-Path "$path"
Set-Location "$path" Set-Location "$path"
Write-Host "📂$path · on branch: " -noNewline Write-Host "📂$path`n🌿on branch: " -noNewline
& git status --short --branch --show-stash & git status --short --branch --show-stash
exit 0 # success exit 0 # success
} catch { } catch {

View File

@ -5,7 +5,7 @@
This PowerShell script queries the status of the SSD/HDD devices (supporting S.M.A.R.T.) and prints it. This PowerShell script queries the status of the SSD/HDD devices (supporting S.M.A.R.T.) and prints it.
.EXAMPLE .EXAMPLE
PS> ./check-smart-devices.ps1 PS> ./check-smart-devices.ps1
1TB Samsung SSD 970 EVO via NVMe (37°C, 2388 hours, 289x on/off, v2B2QEXE7, test passed) 1TB Samsung SSD 970 EVO 1TB via NVMe (35°C, 6142h, 34TB read, 64TB written, 770x on/off, v2B2QEXE7, test passed)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -29,18 +29,15 @@ function Bytes2String([int64]$bytes) {
} }
try { try {
#Write-Progress "(1/3) Searching for smartmontools..."
$result = (smartctl --version) $result = (smartctl --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'smartctl' - make sure smartmontools are installed" } if ($lastExitCode -ne "0") { throw "Can't execute 'smartctl' - make sure smartmontools are installed" }
#Write-Progress "(2/3) Scanning S.M.A.R.T devices..."
if ($IsLinux) { if ($IsLinux) {
$devices = $(sudo smartctl --scan-open) $devices = $(sudo smartctl --scan-open)
} else { } else {
$devices = $(smartctl --scan-open) $devices = $(smartctl --scan-open)
} }
#Write-Progress "Querying S.M.A.R.T devices..."
foreach($device in $devices) { foreach($device in $devices) {
$array = $device.split(" ") $array = $device.split(" ")
$dev = $array[0] $dev = $array[0]
@ -62,37 +59,41 @@ try {
} else { } else {
$capacity = "" $capacity = ""
} }
$infos = ""
if ($details.temperature.current -gt 50) { if ($details.temperature.current -gt 50) {
$temp = "$($details.temperature.current)°C TOO HOT" $infos = "$($details.temperature.current)°C TOO HOT"
$status = "⚠️" $status = "⚠️"
} elseif ($details.temperature.current -lt 0) { } elseif ($details.temperature.current -lt 0) {
$temp = "$($details.temperature.current)°C TOO COLD" $infos = "$($details.temperature.current)°C TOO COLD"
$status = "⚠️" $status = "⚠️"
} else { } else {
$temp = "$($details.temperature.current)°C" $infos = "$($details.temperature.current)°C"
} }
if ($details.power_on_time.hours -gt 87600) { # 10 years if ($details.power_on_time.hours -gt 87600) { # 10 years
$hours = "$($details.power_on_time.hours) hours (!)" $infos += ", $($details.power_on_time.hours)h (!)"
$status = "⚠️" $status = "⚠️"
} else { } else {
$hours = "$($details.power_on_time.hours) hours" $infos += ", $($details.power_on_time.hours)h"
}
if ($details.nvme_smart_health_information_log.host_reads) {
$infos += ", $(Bytes2String ($details.nvme_smart_health_information_log.data_units_read * 512 * 1000)) read"
$infos += ", $(Bytes2String ($details.nvme_smart_health_information_log.data_units_written * 512 * 1000)) written"
} }
if ($details.power_cycle_count -gt 100000) { if ($details.power_cycle_count -gt 100000) {
$powerOn = "$($details.power_cycle_count)x on/off (!)" $infos += ", $($details.power_cycle_count)x on/off (!)"
$status = "⚠️" $status = "⚠️"
} else { } else {
$powerOn = "$($details.power_cycle_count)x on/off" $infos += ", $($details.power_cycle_count)x on/off"
} }
$infos += ", v$($details.firmware_version)"
if ($details.smart_status.passed) { if ($details.smart_status.passed) {
$selftest = "test passed" $infos += ", test passed"
} else { } else {
$selftest = "test FAILED" $infos += ", test FAILED"
$status = "⚠️" $status = "⚠️"
} }
$firmwareVersion = $details.firmware_version Write-Host "$status $capacity$modelName via $protocol ($infos)"
Write-Host "$status $capacity$modelName via $protocol ($temp, $hours, $powerOn, v$firmwareVersion, $selftest)"
} }
#Write-Progress -completed "Done."
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -12,7 +12,7 @@
(2/4) Checking local repository... C:\Repos\rust (2/4) Checking local repository... C:\Repos\rust
(3/4) Removing untracked files in repository... (3/4) Removing untracked files in repository...
(4/4) Removing untracked files in submodules... (4/4) Removing untracked files in submodules...
Repo 📂rust successfully cleaned up in 2s. Cleaned up repo 📂rust in 2s.
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -45,7 +45,7 @@ try {
if ($lastExitCode -ne "0") { throw "'git clean' in the submodules failed with exit code $lastExitCode" } if ($lastExitCode -ne "0") { throw "'git clean' in the submodules failed with exit code $lastExitCode" }
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds [int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"Repo 📂$repoName successfully cleaned up in $($elapsed)s." "Cleaned up repo 📂$repoName in $($elapsed)s."
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -8,7 +8,7 @@
.EXAMPLE .EXAMPLE
PS> ./list-earthquakes.ps1 PS> ./list-earthquakes.ps1
Mag Location Depth Time UTC MAG LOCATION DEPTH TIME UTC
--- -------- ----- -------- --- -------- ----- --------
7.2 98 km S of Sand Point, Alaska 33 km 2023-07-16T06:48:22.606Z 7.2 98 km S of Sand Point, Alaska 33 km 2023-07-16T06:48:22.606Z
... ...
@ -30,13 +30,13 @@ function ListEarthquakes {
foreach($quake in $quakes) { foreach($quake in $quakes) {
[int]$depth = $quake.depth [int]$depth = $quake.depth
New-Object PSObject -Property @{ Mag=$quake.mag; Depth="$depth km"; Location=$quake.place; 'Time UTC'=$quake.time } New-Object PSObject -Property @{ MAG=$quake.mag; DEPTH="$depth km"; LOCATION=$quake.place; 'TIME UTC'=$quake.time }
} }
} }
try { try {
ListEarthquakes | Format-Table -property @{e='Mag';width=5},@{e='Location';width=42},@{e='Depth';width=12},'Time UTC' ListEarthquakes | Format-Table -property @{e='MAG';width=5},@{e='LOCATION';width=50},@{e='DEPTH';width=8},'TIME UTC'
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -7,7 +7,7 @@
Specifies the hostname or IP address to ping (x.com by default) Specifies the hostname or IP address to ping (x.com by default)
.EXAMPLE .EXAMPLE
PS> ./ping-host.ps1 x.com PS> ./ping-host.ps1 x.com
Host 'x.com' is up with 23ms ping latency. Host 'x.com' is UP (20ms latency to IP 104.244.42.65).
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -16,22 +16,18 @@
param([string]$hostname = "x.com") param([string]$hostname = "x.com")
function GetPingLatency([string]$hostname) {
$hostsArray = $hostname.Split(",")
$tasks = $hostsArray | foreach { (New-Object Net.NetworkInformation.Ping).SendPingAsync($_,3000) }
[Threading.Tasks.Task]::WaitAll($tasks)
foreach($ping in $tasks.Result) { if ($ping.Status -eq "Success") { return $ping.RoundtripTime } }
return -1
}
try { try {
[int]$latency = GetPingLatency($hostname) $remoteHosts = $hostname.Split(",")
if ($latency -lt 0) { $tasks = $remoteHosts | foreach { (New-Object Net.NetworkInformation.Ping).SendPingAsync($_,3000) }
Write-Host "⚠️ Host '$hostname' doesn't respond - check the connection or maybe the host is down." [Threading.Tasks.Task]::WaitAll($tasks)
exit 1 foreach($ping in $tasks.Result) {
if ($ping.Status -eq "Success") {
Write-Host "✅ Host '$hostname' is UP ($($ping.RoundtripTime)ms latency to IP $($ping.Address))."
exit 0 # success
}
} }
Write-Host "✅ Host '$hostname' is up with $($latency)ms ping latency." Write-Host "⚠️ Host '$hostname' doesn't respond - check the connection or maybe the host is down (yet)."
exit 0 # success exit 1
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1