I need help saving logs directly to a txt file. I made a simple monitoring script of our servers and computers. Basically I just need to know whether it is online or offline but i need the logs to be save directly whatever the output is.
While ($true) {
$ServerName = Get-Content "E:\ServerList.txt"
foreach ($Server in $ServerName) {
if (test-Connection -ComputerName $Server -Count 3 -quiet ) {
Write-Host "$Server is Online " -ForegroundColor Green ;(Get-Date).toString("yyyy/MM/dd HH:mm:ss")
} else {
Write-Host "$Server - is Offline " -ForegroundColor Red ;(Get-Date).toString("yyyy/MM/dd HH:mm:ss")
}
}
How can I improve it?