Read $headers PowerShell Universal API


I’m trying to save the headers to the eventviewer but the output seems to be: System.Collections.Generic.Dictionary`2[System.String,System.String]
Does anyone know how to convert this into readable text?

Thanks in advance, Johan!

You can convert them to JSON.

$Headers | ConvertTo-Json | Out-File C:\users\adamr\desktop\test.txt

Output looks like this

  "Connection": "Keep-Alive",
  "Accept": "application/json, text/plain, */*",
  "Accept-Encoding": "gzip, deflate, br",
  "Accept-Language": "en-US,en;q=0.9",
  "Host": "localhost:82",
  "Referer": "http://localhost:82/admin/api/1",
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.60",
  "Sec-Fetch-Site": "same-origin",
  "Sec-Fetch-Mode": "cors",
  "Sec-Fetch-Dest": "empty",
  "MS-ASPNETCORE-TOKEN": "ba996881-eb4e-4afc-90b0-a919dadafeaa",
  "X-Original-Proto": "http",
  "X-Original-For": ""