Out-File or Set-Content format is not same as console output

Occasional Contributor

The output that I see on the console looks different from what gets redirected to the file





$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Basic Put BASE64 encoded value of username:password")

$response = Invoke-WebRequest '' -Method 'GET' -Headers $headers



$response.content | set-content -Path "C:\inetpub\wwwroot\\feed_IPV4.txt"

$response.content | out-file -FilePath "C:\inetpub\wwwroot\\feed_IPV4.txt"





Below is what is see in console for $response.content




Below is what is written to file by either set-content or out-file





How can I solve this.

2 Replies
best response confirmed by Rajtoor (Occasional Contributor)



Try to use 




 $response.content | Write-Output >> "C:\inetpub\wwwroot\\feed_IPV4.txt"


yes that worked. And I also found this works.

response.content.split() | out-file -FilePath "C:\inetpub\wwwroot\\feed_IPV4.txt"