mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-22 20:51:17 +01:00
Add list-countries.ps1
This commit is contained in:
parent
6b55c445d3
commit
503a7485f1
@ -92,6 +92,7 @@ list-cheat-sheet.ps1, lists the PowerShell cheat sheet
|
||||
list-city-weather.ps1, lists the current weather of cities worldwide (east to west)
|
||||
list-commits.ps1, lists all commits in the current/given Git repository
|
||||
list-console-colors.ps1, lists all console colors
|
||||
list-countries.ps1, lists details of all countries
|
||||
list-cli-tools.ps1, lists available command-line interface (CLI) tools
|
||||
list-clipboard.ps1, lists the contents of the clipboard
|
||||
list-credits.ps1, shows the credits
|
||||
|
Can't render this file because it has a wrong number of fields in line 85.
|
@ -215,6 +215,7 @@ Mega Collection of PowerShell Scripts
|
||||
* [generate-qrcode.ps1](Scripts/generate-qrcode.ps1) - generates a QR code
|
||||
* [list-anagrams.ps1](Scripts/list-anagrams.ps1) - lists all anagrams of the given word
|
||||
* [list-city-weather.ps1](Scripts/list-city-weather.ps1) - lists the current weather of cities worldwide (west to east)
|
||||
* [list-countries.ps1](Scripts/list-countries.ps1) - lists details of all countries
|
||||
* [list-credits.ps1](Scripts/list-credits.ps1) - shows the credits
|
||||
* [list-crypto-rates.ps1](Scripts/list-crypto-rates.ps1) - lists the current crypto exchange rates
|
||||
* [list-environment-variables.ps1](Scripts/list-environment-variables.ps1) - lists all environment variables
|
||||
|
34
Scripts/list-countries.ps1
Normal file
34
Scripts/list-countries.ps1
Normal file
@ -0,0 +1,34 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
list-countries.ps1
|
||||
.DESCRIPTION
|
||||
Lists details of all countries
|
||||
.EXAMPLE
|
||||
PS> .\list-countries.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz
|
||||
License: CC0
|
||||
#>
|
||||
|
||||
function ListCountries {
|
||||
$Countries = (Invoke-WebRequest -uri "https://restcountries.eu/rest/v2/all" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
|
||||
foreach($Country in $Countries) {
|
||||
New-Object PSObject -Property @{
|
||||
'Country' = "$($Country.Name)"
|
||||
'Capital' = "$($Country.Capital)"
|
||||
'Population' = "$($Country.Population)"
|
||||
'TLD' = "$($Country.TopLevelDomain)"
|
||||
'Phone' = "+$($Country.CallingCodes)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ListCountries | format-table -property Country,Capital,Population,TLD,Phone
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user