Search for File Across Multiple Servers or Roaming Profiles with Powershell

PowerShell logoRecently we need to search a load of servers locally for files that existed ( lingered ) on peoples local user proflile

Get-ChildItem -Recurse -Force \\servername\c$\Users\*\AppData\Local\Temp | Where-Object {$_.Name -like "Z@*.tmp"} | Export-CSV C:\TempFiles.csv -Append

We then needed to search roaming directories mapped on a file server , I tried to use the above for this command replacing the directory location with a roaming file server location replace * with Users again, however I was getting “Get-ChildItem : Access is denied” with UnauthorizedAccessException , probably because query is too generic! To limit this down, I used the following pipe to query the list of users and then check each folder after

Get-ChildItem "\\domain.local\dfs\location\*" | ForEach-Object {
 
Get-ChildItem -Recurse -Force $_"\AppData\Roaming\Software"   | Where-Object {$_.Name -like "Z@*.tmp"}} | Export-CSV C:\Files.csv -Append

 

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 10.00 out of 5)
Loading...