PowerShell/Scripts/what-is.ps1

39 lines
957 B
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2023-01-01 17:47:39 +01:00
Describes an abbreviation
2021-07-13 21:10:02 +02:00
.DESCRIPTION
2022-12-21 08:14:30 +01:00
This PowerShell script queries and prints a description of the given abbreviation.
.PARAMETER abbr
Specifies the abbreviation to look for
2021-07-13 21:10:02 +02:00
.EXAMPLE
2021-11-28 11:57:49 +01:00
PS> ./what-is IAS
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-01-30 10:49:30 +01:00
.NOTES
2022-09-06 21:42:04 +02:00
Author: Markus Fleschutz | License: CC0
2021-04-27 15:54:52 +02:00
#>
2022-12-21 08:14:30 +01:00
param([string]$abbr = "")
2021-11-28 11:57:49 +01:00
2021-04-27 15:54:52 +02:00
try {
2022-12-21 08:14:30 +01:00
if ($abbr -eq "" ) { $abbr = Read-Host "Enter the abbreviation" }
2021-04-29 20:19:07 +02:00
2022-12-21 08:14:30 +01:00
$Missing = $true
$Files = (Get-ChildItem "$PSScriptRoot/../Data/Abbr/*.csv")
2021-05-20 11:30:01 +02:00
foreach ($File in $Files) {
2022-12-21 08:14:30 +01:00
$Table = Import-CSV "$File"
2021-05-20 11:30:01 +02:00
foreach($Row in $Table) {
2023-02-17 14:44:58 +01:00
if ($Row.ABBR -eq $abbr) {
2023-01-02 16:24:29 +01:00
$Basename = (Get-Item "$File").Basename -Replace "_"," "
2023-02-17 14:44:58 +01:00
"💡 In $Basename $($Row.ABBR) may refer to $($Row.TERM)."
2022-12-21 08:14:30 +01:00
$Missing = $false
2021-05-20 11:30:01 +02:00
}
2021-04-27 15:54:52 +02:00
}
}
2022-12-21 08:14:30 +01:00
if ($Missing) { "Sorry, '$abbr' is missing in the database." }
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-04-27 15:54:52 +02:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-04-27 15:54:52 +02:00
exit 1
2023-02-17 14:44:58 +01:00
}