SOLVED

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

Copper 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 'https://abc123.com/feeds/feed_ipv4' -Method 'GET' -Headers $headers

$response.content

#------------------------------

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

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

 

 

 

 

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

 

 

 

1.1.1.1-1.1.1.10
2.2.2.2-2.2.2.20

 

 

 

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

 

 

 

1.1.1.1-1.1.1.102.2.2.2-2.2.2.20

 

 

 

 

How can I solve this.

2 Replies
best response confirmed by Rajtoor (Copper Contributor)
Solution

@Rajtoor 

 

Try to use 

Write-Output 

 

 

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

 

yes that worked. And I also found this works.

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

Accepted Solutions
best response confirmed by Rajtoor (Copper Contributor)
Solution

@Rajtoor 

 

Try to use 

Write-Output 

 

 

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

 

View solution in original post