search script to find a certain file and output the result

by Oct 12, 2011

Hi Guys,

I'd like to make a script to find a certain file on my c: drive.
If it founds the file it must output "file found" (preferably with the path) else "error not found". My script does this but… it gives me "error not found" for all the files that does not match.

$items = Get-ChildItem -Path "c:temp" -recurse
 
foreach ($item in $items)
{
      if ($item -match "file.dll")
      {
            Write-Host "file found"  
      }
    else {
    write-host "error not found"
    }    
}