I found a ping script which is useful, but I'd prefer to write the output to a txt or csv rather than using Write-Host to output to the PS console.
What is the best way of doing this?
I found a ping script which is useful, but I'd prefer to write the output to a txt or csv rather than using Write-Host to output to the PS console.
What is the best way of doing this?
You will need to change the Write-Host to Out-File, or, better still, Out-Default. Using Out-Default will allow you to pipe the output to other cmdlets, and therefore allow you to handle the output differently on different occasions, depending on your particular need at the moment.
Write-Host bypasses the PowerShell pipeline, and effectively removes any objects it uses from the pipeline, making them unavailable for assignment or use by other cmdlets.
References:
Get-Help Write-Host
Get-Help Out-File
Get-Help Out-Default
Out-File, agreed; I hadn't been thinking about performance as a priority - especially as I favor the Out-Default model, where I leave it up to the user of the ping script whether he wants it to go to file or to another cmdlet or wherever, at run time.
Write-Information. Then, redirect theInformationstream to a file.