Link to home
Start Free TrialLog in
Avatar of fireburn11
fireburn11

asked on

Powershell to find if a file exist on 20 servers

Hi All,

I have about 20 Windows OS servers and I need a powershell script that read a text file that contains a list of server names, then go into each server and find out if a particular file exists, if it does, write the host name to fileexsit.txt and it the file doesn't exist, write to a file named filenotexist.txt.

Please help!!


Thanks!
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Something along these lines. Note that myhostname is a fqdn list of hosts one for each row (no header)
I’m writing from memory so syntax may be imprecise.
  $filename = C:\filename
Get-content myhostnames.txt | % {

$result =    Invoke-command -computername $_  -scriptblock { if ( test-file $using:filename ) { $true} else { $false } }
If ( $result ) { $_ >> fileexists.txt} else { $_.name >> fileNOTexists.txt}
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial