forked from fleschutz/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhat-is.ps1
executable file
·40 lines (34 loc) · 986 Bytes
/
what-is.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<#
.SYNOPSIS
Prints a description of the given abbreviation
.DESCRIPTION
what-is.ps1 [<abbreviation>]
.EXAMPLE
PS> ./what-is CIA
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
https://github.com/fleschutz/PowerShell
#>
param([string]$abbreviation = "")
try {
if ($abbreviation -eq "" ) { $abbreviation = read-host "Enter the abbreviation" }
write-progress "Searching ..."
$FoundOne = $false
$Files = (get-childItem "$PSScriptRoot/../Data/Abbr/*" -attributes !Directory)
foreach ($File in $Files) {
$Table = import-csv "$File"
foreach($Row in $Table) {
if ($Row.Abbreviation -eq $abbreviation) {
$Basename = (get-item "$File").Basename
" → $($Row.Abbreviation) = $($Row.Definition) in $Basename"
$FoundOne = $true
}
}
}
if ($FoundOne -eq $false) { "Sorry, no entry for $abbreviation found" }
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}