0
I am trying to create a script in Powershell, and in this script I need to take data from an application in webservice, and when doing the same, just returns as an arrayListObject, instead of the objects themselves.
The script is the following:
$dados = Invoke-RestMethod -Uri 'http://IPADDRESS/DADOS' -Method 'Get'
I’ve tried too:
$dados = Invoke-RestMethod -Uri 'http://IPADDRESS/DADOS' | ConvertTo-Json
$dados = Invoke-RestMethod -Uri 'http://IPADDRESS/DADOS' -Method 'Get' -ContentType "application/json"
What it returns is all the objects in the $data variable, in an arrayListObject, and I can’t manipulate the objects within that array. I can’t select $data.data, for example, just $data.arrayListObject.
It would be good to inform the address where you are getting the data to also do tests since the documentation of cmdlet Invoke-Restmethod informs that cmdlet output depends on the format of the recovered content and if the request returns JSON strings,
Invoke-RestMethod
returns aPSObject
representing the strings. Have you triedConvertTo-Json
– Augusto Vasques
The address is of an intranet that we use, so I thought it was better not to share, since it would not be possible to access. Regarding Convertto-Json, yes I tried to use, but without success.
– Andl
make a Curl at the same address and see if it returns JSON. Example:
curl http://IPADDRESS/DADOS -H "Accept: application/json"
– Augusto Vasques
I was unsuccessful using Curl, but after some searches, I was able to get the page header from Invoke-Webrequest, where it says: [Content-Type, application/json;charset=UTF-8]
– Andl