by flay117 at 2013-02-19 03:10:11
Hi all,by jonhtyler at 2013-02-19 04:33:12
I’m pretty new to powershell, and I’m wondering if anyone could explain how I could run a command on different computers, with the computernames in a text file.
What I need to do is to browse to each computers C:\ and have a look in a text file on each computer, and then paste that info in a text file on my local C: drive. So the command would look something like this: (the computers.txt consist of \computername\c$)
$computer = (get-content computers.txt)
get-content test.txt | out-file -append C:\results.txt
How could I modify this script to be able to do this on each one of these computers, if I put more names into the computers.txt?
Since you are using the UNC convention to address your computers, I am going to assume that this is how you have been accessing the files and that all firewall rules are in place to get to the remote computer and its administrative shares. That being said, you could use something like the following:
foreach ($path in (get-content -path computers.txt))
get-content -path “$path\test.txt” | out-file -path c:\results.txt -append