2021-09-27 10:38:12 +02:00
|
|
|
|
<#
|
2021-08-03 17:01:09 +02:00
|
|
|
|
.SYNOPSIS
|
2021-10-04 21:29:23 +02:00
|
|
|
|
Lists the exchange rates for a currency
|
2021-08-03 17:01:09 +02:00
|
|
|
|
.DESCRIPTION
|
2022-01-29 12:47:46 +01:00
|
|
|
|
This PowerShell script lists the current exchange rates for the given currency (USD per default).
|
2021-10-15 23:09:08 +02:00
|
|
|
|
.PARAMETER currency
|
|
|
|
|
Specifies the base currency
|
2021-08-03 17:01:09 +02:00
|
|
|
|
.EXAMPLE
|
2021-09-24 17:19:49 +02:00
|
|
|
|
PS> ./list-exchange-rates EUR
|
2021-08-03 17:01:09 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-01-29 12:47:46 +01:00
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz / License: CC0
|
2021-08-03 17:01:09 +02:00
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
param([string]$currency = "USD")
|
|
|
|
|
|
2021-08-03 19:41:50 +02:00
|
|
|
|
function ListExchangeRates { param([string]$currency)
|
|
|
|
|
[xml]$ExchangeRates = (invoke-webRequest -uri "http://www.floatrates.com/daily/$($currency).xml" -userAgent "curl" -useBasicParsing).Content
|
|
|
|
|
foreach($Row in $ExchangeRates.channel.item) {
|
|
|
|
|
new-object PSObject -property @{ 'Rate' = "$($Row.exchangeRate)"; 'Currency' = "$($Row.targetCurrency) - $($Row.targetName)"; 'Inverse' = "$($Row.inverseRate)"; 'Date' = "$($Row.pubDate)" }
|
2021-08-03 17:01:09 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
""
|
2021-08-26 16:59:23 +02:00
|
|
|
|
"Current Exchange Rates for 1 $currency (source: http://www.floatrates.com)"
|
|
|
|
|
"================================"
|
2021-08-03 17:01:09 +02:00
|
|
|
|
|
2021-08-03 19:41:50 +02:00
|
|
|
|
ListExchangeRates $currency | format-table -property Rate,Currency,Inverse,Date
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2021-08-03 17:01:09 +02:00
|
|
|
|
} catch {
|
2021-09-16 20:19:10 +02:00
|
|
|
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
2021-08-03 17:01:09 +02:00
|
|
|
|
exit 1
|
|
|
|
|
}
|