简体   繁体   中英

Is there a Powershell equivalent to JavaScript Console Log?

I have a powershell script, which is calling a third party API and getting some response data back. I'd like to just log the response object to see what exactly is returning. I've tried

Write-Host ($item | Format-List | Out-String)

But that doesn't seem to be working. The API says it will return JSON but I'm not sure how to verify the return at all.

Full script is something like this.

$queryURL = "xyz"
$apiResponse = Invoke-RestMethod -Uri $queryURL -Method Get -ContentType "application/json" -Headers $header

You can pipe the Invoke-RestMethod to the ConvertFrom-Json cmdlet, this will convert the output into an object you can easily query:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-7.1

$j = Invoke-WebRequest 'https://api.github.com/repos/PowerShell/PowerShell/issues' | ConvertFrom-Json

Calling $j will output the object created from the JSON.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM