PowerShell/Scripts/list-exchange-rates.ps1

34 lines
1.1 KiB
PowerShell
Raw Normal View History

2021-08-03 17:01:09 +02:00
<#
.SYNOPSIS
list-exchange-rates.ps1 [<currency>]
.DESCRIPTION
2021-08-29 17:50:03 +02:00
Lists the current exchange rates for the given currency (USD per default).
2021-08-03 17:01:09 +02:00
.EXAMPLE
2021-08-26 16:59:23 +02:00
PS> .\list-exchange-rates.ps1 EUR
2021-08-29 17:50:03 +02:00
.NOTES
Author: Markus Fleschutz · License: CC0
2021-08-03 17:01:09 +02:00
.LINK
https://github.com/fleschutz/PowerShell
#>
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-08-03 17:01:09 +02:00
exit 0
} catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}