2023-07-29 09:55:25 +02:00
|
|
|
## Script: *locate-city.ps1*
|
2021-11-08 21:36:42 +01:00
|
|
|
|
2022-02-10 09:01:07 +01:00
|
|
|
This PowerShell script prints the geographic location of the given city.
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
## Parameters
|
|
|
|
```powershell
|
2023-07-29 09:45:37 +02:00
|
|
|
locate-city.ps1 [[-City] <String>] [<CommonParameters>]
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
-City <String>
|
|
|
|
Specifies the city to look for
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
```powershell
|
|
|
|
PS> ./locate-city Paris
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Notes
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
## Related Links
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2023-07-29 09:55:25 +02:00
|
|
|
## Script Content
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Prints the geographic location of a city
|
|
|
|
.DESCRIPTION
|
|
|
|
This PowerShell script prints the geographic location of the given city.
|
|
|
|
.PARAMETER City
|
|
|
|
Specifies the city to look for
|
|
|
|
.EXAMPLE
|
|
|
|
PS> ./locate-city Paris
|
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
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 in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-07-29 09:55:25 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of locate-city.ps1 as of 07/29/2023 09:55:13)*
|