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.<\/p>\n
$ClientName = Get-AdObject -Filter * -Searchbase ‘OU=Computers,DC=MyDomain,DC=local’| Select Name<\/p>\n
ForEach ($Client in $ClientName)
\n{
\n$UserName = Get-ChildItem \\$Client\\c$\\users\\ | Select Name<\/p>\n
ForEach ($User in $UserName) } Try changing your first line from:<\/p>\n To:<\/p>\n Piping to expand will make it an array without the property.<\/p>","upvoteCount":4,"datePublished":"2015-08-24T18:35:48.000Z","url":"https://community.spiceworks.com/t/powershell-script/430234/2","author":{"@type":"Person","name":"chamele0n","url":"https://community.spiceworks.com/u/chamele0n"}},"suggestedAnswer":[{"@type":"Answer","text":" 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.<\/p>\n $ClientName = Get-AdObject -Filter * -Searchbase ‘OU=Computers,DC=MyDomain,DC=local’| Select Name<\/p>\n ForEach ($Client in $ClientName) ForEach ($User in $UserName) } 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.<\/p>","upvoteCount":3,"datePublished":"2015-08-24T18:36:53.000Z","url":"https://community.spiceworks.com/t/powershell-script/430234/3","author":{"@type":"Person","name":"chamele0n","url":"https://community.spiceworks.com/u/chamele0n"}},{"@type":"Answer","text":" 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!<\/p>\n If anyone ever needs a way to search all your computers for the Browsec Extension in Chrome, this will do it.<\/p>\n
\n{
\nGet-ChildItem \\$Client\\c$\\users$User\\AppData\\Local\\Google\\Chrome\"User Data\"\\Default\\Extensions\\ -Filter omghf<\/em>. -Recurse -Force<\/p>\n
\n}<\/p>","upvoteCount":7,"answerCount":4,"datePublished":"2015-08-24T18:23:20.000Z","author":{"@type":"Person","name":"rayray72","url":"https://community.spiceworks.com/u/rayray72"},"acceptedAnswer":{"@type":"Answer","text":"$ClientName = Get-AdObject -Filter * -Searchbase 'OU=Computers,DC=MyDomain,DC=local'| Select Name\n<\/code><\/pre>\n
$ClientName = Get-AdObject -Filter * -Searchbase 'OU=Computers,DC=MyDomain,DC=local' | Select -ExpandProperty Name\n<\/code><\/pre>\n
\n{
\n$UserName = Get-ChildItem \\$Client\\c$\\users\\ | Select Name<\/p>\n
\n{
\nGet-ChildItem \\$Client\\c$\\users$User\\AppData\\Local\\Google\\Chrome\"User Data\"\\Default\\Extensions\\ -Filter omghf<\/em>. -Recurse -Force<\/p>\n
\n}<\/p>","upvoteCount":7,"datePublished":"2015-08-24T18:23:20.000Z","url":"https://community.spiceworks.com/t/powershell-script/430234/1","author":{"@type":"Person","name":"rayray72","url":"https://community.spiceworks.com/u/rayray72"}},{"@type":"Answer","text":"$ClientName = Get-AdObject -Filter * -Searchbase 'OU=Computers,DC=Domain,DC=local'| Select -ExpandProperty Name\n\nForEach ($Client in $ClientName)\n{\n $UserName = Get-ChildItem \\\\$Client\\c$\\users\\ | Select -ExpandProperty Name\n \n ForEach ($User in $UserName)\n {\n Get-ChildItem \\\\$Client\\c$\\users\\$User\\AppData\\Local\\Google\\Chrome\\\"User Data\"\\Default\\Extensions\\ -Filter *omghf*. -Recurse -Force\n\n }\n} \n<\/code><\/pre>","upvoteCount":0,"datePublished":"2015-08-25T10:00:01.000Z","url":"https://community.spiceworks.com/t/powershell-script/430234/4","author":{"@type":"Person","name":"rayray72","url":"https://community.spiceworks.com/u/rayray72"}}]}}