# Currency fonverson rates function

**URL:** <https://forums.powershell.org/t/currency-fonverson-rates-function/15960>\
**Category:** PowerShell Help\
**Created:** [March 13, 2021, 4:18pm UTC](https://forums.powershell.org/t/currency-fonverson-rates-function/15960 "2021-03-13T16:18:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pozso123](https://avatars.discourse-cdn.com/v4/letter/p/ccd318/32.png) [@pozso123](https://forums.powershell.org/u/pozso123)\
**Post date:** [March 13, 2021, 4:18pm UTC](https://forums.powershell.org/t/currency-fonverson-rates-function/15960/1 "2021-03-13T16:18:09Z")

</div>

Hello i would like to prepare a Currency converter Function which in the first step display rates in an specific days:

```auto
Function Get-Rates {
>>
>> $ConversionRate=New-Object System.Data.DataSet
>>
>> $ConversionRate.Tables.Add("tstable")
>> $Currency=(New-WebServiceProxy -Uri http://currencyconverter.kowabunga.net/converter.asmx?WSDL)
>> $ConversionRate.Tables["tstable"].Columns.Add($Currency.GetCurrencyRates("3/5/2021"))
>>
>> $( $ConversionRate.Tables["tstable"]) | foreach {
>> write-host "Name value is : "$_.name
>> write-host "Nath value is : "$_.path
>> }
>> }

```

I have located an section in XML which contain type of it (so it is date time format):

```auto
<s:element name="GetCurrencyRates">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="RateDate" type="s:dateTime"/>
</s:sequence>
</s:complexType>
</s:element>

```

I have tryed with get-date -format “HH/dd/yyyy”

The point is to able to loop throught the returned Datatable object. But as though it not return anything

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [March 13, 2021, 9:47pm UTC](https://forums.powershell.org/t/currency-fonverson-rates-function/15960/2 "2021-03-13T21:47:01Z")

</div>

Looking through [the documentation for this API](http://currencyconverter.kowabunga.net/converter.asmx?op=GetCurrencyRates), I think you might be over complicating things. Here’s a basic example I cobbled together which I think achieves what you’re trying to do.

```auto
function Get-Rates {

    param (
    
        [Parameter()]
        $date = (Get-Date -Format 'MM/dd/yyyy')

    )

    $uri = "http://currencyconverter.kowabunga.net/converter.asmx/GetCurrencyRates?RateDate=$date"
    $response = Invoke-RestMethod -Uri $uri -Method Get
    $response.DataSet.diffgram.NewDataSet.table | Select-Object Description,Rate

}

Get-Rates -date '03/01/2021'

```

---

<div class="post-metadata">

**Author:** ![pozso123](https://avatars.discourse-cdn.com/v4/letter/p/ccd318/32.png) [@pozso123](https://forums.powershell.org/u/pozso123)\
**Post date:** [March 13, 2021, 10:02pm UTC](https://forums.powershell.org/t/currency-fonverson-rates-function/15960/3 "2021-03-13T22:02:49Z")

</div>

> [@matt-bloomfield](#):
>
> `$response.DataSet.diffgram.NewDataSet.table`

Can you help me how you know that:

```auto
$response.DataSet.diffgram.NewDataSet.table

```

.diffgram is?

.NewDataSet?

.table?

I mean, what does it?

So we have an object by invoke-restmethod output. How do i know i need the refer to .DataSet.diffgram.NewDataSet.table ?

Sory i am an beginner 😃

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [March 13, 2021, 10:47pm UTC](https://forums.powershell.org/t/currency-fonverson-rates-function/15960/4 "2021-03-13T22:47:07Z")

</div>

It’s really just a case of drilling down until you get what you want 🙂

When we type `$response` at the prompt, we see the two properties `xml` and `DataSet`, so then we try `$response.DataSet`. That gives the next three properties and so on.

---

<div class="post-metadata">

**Author:** ![pozso123](https://avatars.discourse-cdn.com/v4/letter/p/ccd318/32.png) [@pozso123](https://forums.powershell.org/u/pozso123)\
**Post date:** [March 13, 2021, 11:01pm UTC](https://forums.powershell.org/t/currency-fonverson-rates-function/15960/5 "2021-03-13T23:01:14Z")

</div>

In time i edited in my shell the function, it not offered property as normal. So i greb that 2 line, and beginning to write and after $response it offered it yet.

So i would find a better option to discover the object what i am working with. So i found the Get-Member cmdlet which get the pipeline input of that and list all available methid, alias, propertys and so on. So the only missing things is go deaper in the object without get directly it from pipeline

So i guess:

```auto
$response| Get-Member -MemberTypes Property

```

output

> Name MemberType Definition
> 
> * * *
> 
> DataSet Property System.Xml.XmlElement DataSet {get;}  
> xml Property string xml {get;set;}

Than i cannot discover or peak into to DataSet property without calling it from original object

```auto
$response.DataSet| Get-Member -MemberTypes Property

```

> Name MemberType Definition
> 
> * * *
> 
> diffgram Property System.Xml.XmlElement diffgram {get;}  
> schema Property System.Xml.XmlElement schema {get;}  
> xmlns Property string xmlns {get;set;}

Do you have any idea for that ?

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [March 14, 2021, 12:18pm UTC](https://forums.powershell.org/t/currency-fonverson-rates-function/15960/6 "2021-03-14T12:18:04Z")

</div>

Discovering the child nodes is always going to involve inspecting the returned XML in some way or another. I think using the dot notation, is probably the quickest way. Although you could use `$response.InnerXML` to look at the document structure.  
Perhaps someone with more experience working with XML can advise on what techniques they would use.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:27pm UTC](https://forums.powershell.org/t/currency-fonverson-rates-function/15960/7 "2024-05-16T20:27:44Z")

</div>

Closed on May 16, 2024, 8:27pm UTC


