mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-24 15:49:02 +01:00
44 lines
966 B
PowerShell
Executable File
44 lines
966 B
PowerShell
Executable File
<#
|
|
.SYNOPSIS
|
|
Prints the geographic location of the given city
|
|
.DESCRIPTION
|
|
locate-city.ps1 [<City>]
|
|
.EXAMPLE
|
|
PS> ./locate-city Paris
|
|
.NOTES
|
|
Author: Markus Fleschutz · License: CC0
|
|
.LINK
|
|
https://github.com/fleschutz/PowerShell
|
|
#>
|
|
|
|
param([string]$City = "")
|
|
|
|
try {
|
|
if ($City -eq "" ) { $City = read-host "Enter the city name" }
|
|
|
|
write-progress "Reading worldcities.csv..."
|
|
$Table = import-csv "$PSScriptRoot/../Data/worldcities.csv"
|
|
|
|
$FoundOne = 0
|
|
foreach($Row in $Table) {
|
|
if ($Row.city -eq $City) {
|
|
$FoundOne = 1
|
|
$Country = $Row.country
|
|
$Region = $Row.admin_name
|
|
$Lat = $Row.lat
|
|
$Long = $Row.lng
|
|
$Population = $Row.population
|
|
write-host "* $City ($Country, $Region, population $Population) is at $Lat°N, $Long°W"
|
|
}
|
|
}
|
|
|
|
if ($FoundOne) {
|
|
exit 0 # success
|
|
}
|
|
write-error "City $City not found"
|
|
exit 1
|
|
} catch {
|
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
|
exit 1
|
|
}
|