print content

 To print the full content data from your Invoke-WebRequest in PowerShell, you need to access and output the Content property of the response object. Below is the adjusted PowerShell code to do this:

PowerShell Code to Print Full Content:

powershell
# Send the POST request $response = Invoke-WebRequest -Method POST -Headers @{'x-snow-auth' = 'c8c135a0-05fc-4d2a-8f23-af7f24d66a9c'} -Body "{}" -Uri "https://dev-api.cmnow-dev.ubsdev.net/query?collection=sc_req_item" # Print the entire content of the response Write-Output "Status Code: $($response.StatusCode)" Write-Output "Status Description: $($response.StatusDescription)" Write-Output "Full Response Content:" Write-Output $response.Content

Explanation:

  1. Invoke-WebRequest:

    • Sends the POST request to the API with the appropriate Headers and Body.
    • $response stores the result, which includes properties like StatusCode, StatusDescription, Content, etc.
  2. Content Output:

    • $response.Content holds the body of the response (the Content field), which is typically the JSON or text data returned from the API. This command will print the complete response.

Optional: Parsing the JSON Response

If the response content is in JSON format, and you want to manipulate the data, you can convert it to a PowerShell object and then print specific fields or the entire object.

powershell
# Convert the JSON response content to a PowerShell object $jsonResponse = $response.Content | ConvertFrom-Json # Print the parsed JSON content Write-Output $jsonResponse # Example: Access specific fields from the JSON response Write-Output "RITM Number: $($jsonResponse.results[0].number)" Write-Output "REQ Number: $($jsonResponse.results[0].request.display_value)"

Notes:

  • If the Content contains large JSON data, it may be truncated in the console. The ConvertFrom-Json method will allow you to work with it as a structured PowerShell object.
  • Ensure that the token and URL are correctly formatted and updated for your use case.

Let me know if you need further assistance!

No comments

Theme images by tjasam. Powered by Blogger.