I am looking to search for a file on a list of computers (Computers.txt) and if the file is found I would like the content (it is only 1 line) to be sent to a text file with the computer name and then the content. If the file is not found I would like the output to have the computer name and something like "File not found".
I have this so far:
Get-Content D:\Powershell\computers.txt |
ForEach-Object {Get-Content "\\$_\c$\Temp\Log.txt"} |
Out-File D:\Powershell\DynamicsUpdates.txt
It looks for the file, but some of the computers do not have it and I get errors in the prompt and not the output file. The computers I know this is on do not error, but nothing is written to the output file.
My computers.txt looks like this:
Computer1
Computer2
Computer3
Computer4
MI would like my DynamicsUpdates.txt to read similar to this:
Computer1
<file content>
Computer2
<file contents>
Computer3
File not found
Computer4
File not found
Whatever is easier on the output file is fine, if putting the name and results on one line is easier that is fine as well. I guess i am not searching properly and I am new to this, but this is as far as I have gotten.
Thank you for your assistance in this and i am not adverse to learning if you do not want to write it for me i am also looking for help on how this is done so I can do it for myself soon.