Hello,
I am new to scripting and trying to find a way to search for a supposed virus file named wsr[any two numbers]zt32.dll on a large group of computers. I'm not sure how or where to use Get-ChildItem -Path C:\Users -Filter ?zt32.dll -Recurse | export-csv C:\scripts\output\test.csv in this script.
The below script keeps erroring out when I try messing with the Test-Path options and I'm not sure where to use Get-ChildItem or whatever to get this working. Thanks
##########################################################
# Edit these variables to fit your enviroment
##########################################################
# Set file to be tested for, put everything after c:\
# “c:\Users\Default” is the example path
$filetofind = ‘wsr*zt32.dll ‘
# Hostnames TXT Location
$hostnamestxt = ‘C:\scripts\computernames.txt‘
# Destination file for Online Machines
$onlinetxt = ‘C:\scripts\output\Machines_with_file.txt‘
# Destination file for Offline Machines
$offlinetxt = ‘C:\scripts\output\Offline_Machines.txt‘
##########################################################
# Begin Executing Script – Do Not Edit Below This Line
##########################################################
$computers = get-content “$hostnamestxt”
write-host “———————————————-”
write-host “Scanning hostnames from $hostnamestxt…”
write-host “———————————————-”
foreach($computer in $computers)
{
ping -n 1 $computer >$null
if($lastexitcode -eq 0)
{
if(test-path “\\$computer\c:\users\* -include $filetofind”)
{
echo “$computer” | Out-File -Append “$onlinetxt”
write-host “File FOUND on $computer”
}
else
{write-host “File NOT found on $computer”}
}
else
{
echo “$computer” | Out-File -Append “$offlinetxt”
write-host “$computer is OFFLINE/DID NOT RESPOND TO PING”
}
}
write-host “———————————————-”
write-host “Script has completed please check output.”
write-host “Hosts with file output location – $onlinetxt”
write-host “Hosts that were unpingable output location – $offlinetxt”
write-host “———————————————-”