forked from fleschutz/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocate-zip-code.ps1
More file actions
executable file
·45 lines (40 loc) · 1.11 KB
/
Copy pathlocate-zip-code.ps1
File metadata and controls
executable file
·45 lines (40 loc) · 1.11 KB
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
41
42
43
44
45
#!/snap/bin/powershell
<#
.SYNTAX ./locate-zip-code.ps1 [<country-code>] [<zip-code>]
.DESCRIPTION prints the geographic location of the given zip-code
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param([string]$CountryCode = "", [string]$ZipCode = "")
$PathToRepo = "$PSScriptRoot/.."
try {
if ($CountryCode -eq "" ) {
$CountryCode = read-host "Enter the country code"
}
if ($ZipCode -eq "" ) {
$ZipCode = read-host "Enter the zip code"
}
write-progress "Reading zip-codes.csv..."
$Table = import-csv "$PathToRepo/Data/zip-codes.csv"
$FoundOne = 0
foreach($Row in $Table) {
if ($Row.country -eq $CountryCode) {
if ($Row.postal_code -eq $ZipCode) {
$Country=$Row.country
$City = $Row.city
$Lat = $Row.latitude
$Lon = $Row.longitude
write-output "* $Country $ZipCode $City is at $Lat°N, $Lon°W"
$FoundOne = 1
}
}
}
if ($FoundOne) {
exit 0
}
write-error "Zip-code $ZipCode in country $CountryCode not found"
exit 1
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}