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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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}
}