1

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?

4

1 回答 1

1

为什么不使用 AD-GetComputer 将所有 PC 名称提取到一个变量中?

您也可以使用 export-csv 这对您更有效:

$Computers= Get-ADComputer  -Filter * -SearchBase "ou=accounting,dc=domain,dc=com" -Properties * |     
Select  -ExpandProperty name 

foreach ($computer in $Computers)
    {

    Get-ChildItem \\$computer\c$\users\*\AppData\Roaming\*.dll -recurse | Export-Csv    
    C:\temp\file_check -append -noclobber
     }

要仅返回 DLL 的名称,您可以将 Get-ChildItem 行更改为:

     Get-ChildItem \\$computer\c$\users\*\AppData\Roaming\*.dll -recurse | Select-Object Name | Export-Csv    
     C:\temp\file_check -append -noclobber
于 2014-11-13T20:38:16.363 回答