I don’t have much Powershell scripting experience so I am hoping someone can point me in the right direction. I am trying to search for a file/folder for each user that has logged into each computer in a specific OU. With the script below if I Echo $Client I get each computer name (ie: pc01) from the first line as expected. However on the second line instead of the computer name being added to the UNC path, it makes the path \@{Name=pc1}\c$\users\ and fails to find the directory. I don’t understand why its adding the @{Name= } to the UNC path along with the computer name.

$ClientName = Get-AdObject -Filter * -Searchbase ‘OU=Computers,DC=MyDomain,DC=local’| Select Name

ForEach ($Client in $ClientName)
{
$UserName = Get-ChildItem \$Client\c$\users\ | Select Name

ForEach ($User in $UserName)
{
Get-ChildItem \$Client\c$\users$User\AppData\Local\Google\Chrome"User Data"\Default\Extensions\ -Filter omghf. -Recurse -Force

}
}

7 Spice ups

Try changing your first line from:

$ClientName = Get-AdObject -Filter * -Searchbase 'OU=Computers,DC=MyDomain,DC=local'| Select Name

To:

$ClientName = Get-AdObject -Filter * -Searchbase 'OU=Computers,DC=MyDomain,DC=local' | Select -ExpandProperty Name

Piping to expand will make it an array without the property.

4 Spice ups

Also, when posting code be sure to use the code button < /> at the top of the editor that you;re typing it in. Be sure to select the appropriate language (PowerShell in this case) make it much easier to read the code with syntax highlighting.

3 Spice ups

Thank you Chamele0n, that worked perfectly! I Googled for hours looking for a way to do this. Once I added “-ExpandProperty” to lines 1 and 2 it started searching as expected. I need to add a filter and save the results to a file now, but I can figure that part out. Thank you again!

If anyone ever needs a way to search all your computers for the Browsec Extension in Chrome, this will do it.

$ClientName = Get-AdObject -Filter * -Searchbase 'OU=Computers,DC=Domain,DC=local'| Select -ExpandProperty Name

ForEach ($Client in $ClientName)
{
    $UserName = Get-ChildItem \\$Client\c$\users\ | Select -ExpandProperty Name
    
    ForEach ($User in $UserName)
    {
        Get-ChildItem \\$Client\c$\users\$User\AppData\Local\Google\Chrome\"User Data"\Default\Extensions\ -Filter *omghf*. -Recurse -Force

    }
}