Hi
I have this basic script that goes through a text file to ping all listed IP addresses to see if active.
I'm trying to output the results of this script to a txt file, that I can auto email results in form of an attachment once a day.
pingsweep.ps1
Get-Content c:\IPrange2.txt | ForEach { # Use the Test-Connection cmdlet to determine if the machine is responding $pinged = Test-Connection -ComputerName $_ -Count 1 -Quiet # Use an If statement to determine if the machine responded or not and output accordingly If ($pinged) { Write-Host "$_ - OK" } Else { Write-Host "$_ - No Reply"} }
I have tried to create another script to pipe the output to a file, but the file is always blank
.\pingsweep.ps1 | out-file "c:\output.txt"
or
.\pingsweep.ps1 > "c:\output.txt"
please help, as I have spent a go while trying to figure this out.
Cheers