Search code examples
xmlrestpowershellgetpostman

PowerShell: call XML REST service and print it in readable manner


I have a call to a REST service through PowerShell.

What the query return is in XML and I need to have it printable in the terminal in a readable manner.

The call is easy:

$Url = "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=94107"

Invoke-RestMethod -Method 'GET' -Uri $url 

the result is horrible:

enter image description here

As you can see it's more than readable on Postman but not on the terminal.

Is there a way to print the output in a readable manner on the terminal?

I need to indent all that <?xml version="1.0" encoding="UTF-8"?>, I want to see it printed on the terminal.


Solution

  • $Url = "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=94107"
    $rest = Invoke-RestMethod -Method 'GET' -Uri $url
    $rest.location     #-> readable
    
    # or
    
    $rest.InnerXml    #-> like postman output