2024-10-01 13:37:53 +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
|
2023-08-06 21:35:36 +02:00
|
|
|
PS> ./list-exchange-rates.ps1 EUR
|
|
|
|
|
|
|
|
Current Exchange Rates for 1 EUR (source: http://www.floatrates.com)
|
|
|
|
================================
|
|
|
|
|
|
|
|
Rate Currency Inverse Date
|
|
|
|
---- -------- ------- ----
|
|
|
|
1.09489154 USD - U.S. Dollar 0.91333248 Sun, 6 Aug 2023 11:55:02 GMT
|
|
|
|
...
|
2021-08-03 17:01:09 +02:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-01-29 12:47:46 +01:00
|
|
|
.NOTES
|
2022-09-06 21:42:04 +02:00
|
|
|
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 {
|
2022-04-13 12:06:32 +02:00
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-08-03 17:01:09 +02:00
|
|
|
exit 1
|
|
|
|
}
|