Home > Blockchain >  Powershell Get and Use XML Content from URL
Powershell Get and Use XML Content from URL

Time:02-09

I can query the VPN users of our firewall via API-Call in Chrome.
https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA10g000000Clor

I would like to use result.content as XML in Powershell to work with the objects.

$url=https://localfirewall.domain.tld/api/?type=op&cmd=<show><global-protect-gateway><current-user></current-user></global-protect-gateway></show>&verysecretapikey=
$result=invoke-webrequest -uri $url -skipcertificatechek -method:get -contenttype "application/xml
$result.content

In PaloAlto's KB article you can see the output of the call in the browser.

CodePudding user response:

A string containing well-formed xml is implicitly parsed if you simply convert it to the [xml] type:

# using the `-as` conversion operator
# this will silently return $null on failure to parse the document
$xmlDocument = $result.content -as [xml]

# using a cast operation
# this will throw on failure to parse the document
$xmlDocument = [xml]$result.content
  •  Tags:  
  • Related