I'm attempting to read a list of computer names from a file and scan each for DLL files in a certain set of directories. Basically, I want it to scan every user's personal directory on the PC and look for any DLL files in the ..\AppData\Roaming\ directory.
This is not elegant by any means, but I'm new to PowerShell:
#runs DSQuery to get a list of machine names and export to a text file
c:\temp\get_pc_list.bat
$pcList = Get-Content c:\temp\pc_list.txt
#Removes a blank space at the end of each item in the text file
$pcList | foreach {$_.TrimEnd()} | Set-Content c:\temp\pc_list.txt
del C:\temp\file_check.txt
foreach ($computer in $pcList)
{
Get-ChildItem \\$computer\c$\users\*\AppData\Roaming\*.dll -recurse | Out-File -encoding unicode $("C:\temp\file_check.txt") -append -noclobber
}
When I run it, I get a message that "an object at the specified path \PC101 \c$\users does not exist." It appears that it's adding a space after "PC101", which is the first item in my list. I've checked the file there are no extra spaces at the end of each line.
I've tried enclosing the path in double quotes, but the result is the same. Am I missing something or is it not possible to use a variable in the path?