Using powershell to search for files with date and owner criteria
I recently had a requirement to search some file servers for files that were modified between 2 date ranges and then filter that output by owner.
After some googleing I came up with the following script with a commented out line that would allow a copy of those files after indexing.
———————————————————————————-
$path = Read-Host “Please enter the top-level path (eg: C:\Temp)”
$user = Read-Host “Please enter the user to be searched for (eg: DOMAIN\User)”
$dst = Read-Host “Please enter the copy destination:”
$files = Get-childitem $path -recurse |
where {$_.lastwritetime.date -gt
[datetime]::parse(“01/01/2010″) -and
$_.lastwritetime.date -lt
[datetime]::parse(“01/01/2011″)}
foreach ($file in $files){
$owner = Get-Acl $file.FullName
if ($owner.Owner -eq $user){Write-output $file.FullName >> output}
#if ($owner.Owner -eq $user){copy-item -path $file.FullName -dest $dst -force}
else {}
}