Share via


Windows PowerShell: How to Find Files by Owner

IT pros often have to perform routine file management tasks. For example, when an employee leaves the company, they need to find all the files owned by that specific user in situations so they can move, delete or change the owner of those files. With manual methods, these tasks take a lot of time, so you might want to automate them with Windows PowerShell scripts. For instance, the PowerShell script provided above enables you to find all files on a share or in a specified folder that have a particular owner in their ACL by using the Get-ChildItem and Get-Acl cmdlets. However, even with this script, generating the output file can take a lot of time if there are many files to parse on your file server.

1. Open the PowerShell ISE → Run the following script on the workstation, specifying the network path of a file share or file system, the file owner’s name and the file path for export to csv:

[String]$username = "enterprise\t.simpson"
[String]$username = "enterprise\t.simpson"
[String]$outfile = "C:\scripts\searchowner.csv"
$path = Get-ChildItem "\\pdc\shared\HR"  -Recurse
Foreach( $file in $path ) {
  $f = Get-Acl $file.FullName
  if( $f.Owner -eq $username ) {
    Write-Host( "{0}"-f $file.FullName | Out-File `
      -Encoding "UTF8" `
      -FilePath $outfile -Append)
  }
}

2. Open the file produced by the script in MS Excel.

https://img.netwrix.com/howtos/find_files_by_owner_using_powershell.png

Originally posted: https://www.netwrix.com/how_find_files_by_owner.html