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 "[email protected]*.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 "[email protected]*.tmp"}} | Export-CSV C:\Files.csv -Append

 

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Tags: AppData, find files, Get-ChildItem : Access is denied, local profile, powershell, roaming profile, Search, UnauthorizedAccessException

Trackback from your site.