Hi, I have the following script that checks the windows host file and returns a value based on the lines in the host file. For example, if a host file has an entry in it (that not remarked or 127.0.0.1) it will return an entry number. so if the host file has 1 entry in it the script will out put value 1, and if no entry it will not output any value. The script:
$counter = 0 foreach ($record in Select-String -pattern "^#","^127.0.0.1" -Path C:\Windows\System32\drivers\etc\hosts -NotMatch ) { if ($record.Line.length -gt 8) { $counter = $counter + 1 } } if ($counter -ne 0) { Write-Host $counter }
Now, I want to run this script on multiple servers that I monitor and trigger an alert if it returns a value.
Can anyone please help?
Thanks in advance.
Add comment