Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Basic powerscript to output for loop to file and email

$
0
0

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


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>