I'm querying an API in Powershell and can successfully return the expected results in the console with the following command:
$response.rows.name.Split("`n") | Sort-Object | ForEach-Object { Write-Host $_.Substring(0,$_.IndexOf('.')) }
Now I'm trying to output the results to a text file, but am stumbling over the syntax. This is what I'm trying:
$response.rows.name.Split("`n") | Sort-Object | ForEach-Object { Write-Host $_.Substring(0,$_.IndexOf('.')) } | Out-File $results_file
The expected results still show in the console and the text file is generated, but it is empty. Any advice to point me in the right direction is much appreciated.