Hi,
I am a newbie to powershell and have been trying to work out a script to query event logs on multiple machines (that's Windows XP machines). The reason being is to determine is they have any bad sectors/blocks on their hard drives.
If they do, the events get logged in the system portion of the event logs and I have managed (with the help of google and various forums) to script together the following code to look in the system logs for a disk error event.
It does work and has found the events needed, but it's slow. I have over 1000 machines to check and my question is. Is there a more efficient way of doing this? Is it possible to setup multi threading so I can check say 100 machines at a time? Or is there another way of doing this that I have not found?
Thanks
James
$ErrorActionPreference = "SilentlyContinue"
$servers=get-content d:\temp\machines.txt
$Good="Good"
$Bad="Bad"
$Ugly="Ugly"
$file="d:\temp\output.csv"
add-content $file "Machine Name,Hard Drive State"
foreach ($server in $servers)
{
$server
$arr=$null
if (test-connection $server -quiet –count 01)
{
$arr+=get-eventlog -logname system –EntryType Error –Source “disk” -newest 1 -computer $server | select Message
trap {add-content $file "$server,$Ugly"; Continue}
if ($arr)
{add-content $file "$server,$Bad"}
else
{add-content $file "$server,$Good"}
}
else
{add-content $file "$server,offline"}
}