Retrieve full path and file permissions of file modified between date range in powershell

I suppose it’s the comment after select-object that messed up everything, because there’s a linebreak after and the hashtables will not be passed as arguments to the command. Also there was an issue in your Expression definitions (you have to put them in a script block {}).

This should work:

$BaseFolder = "<path to be traversed>"

[datetime]$start = '2019-10-05 00:00:00'
[datetime]$end = '2020-10-25 00:00:00'

$Acl = Get-Acl -Path $BaseFolder

$Files = ForEach ($Access in $Acl.Access){
    Get-ChildItem -Path $BaseFolder -Recurse -Force |
        Where-Object { $_.LastWriteTime -gt $start -AND $_.LastWriteTime -lt $end } | 
        Select-Object @{Name='Path';Expression={$_.FullName}},
                      @{Name='LastWriteTime';Expression={$_.LastWriteTime}},
                      @{Name='Group/User';Expression={$Access.IdentityReference}},
                      @{Name='Permissions';Expression={$Access.FileSystemRights}},
                      @{Name='Inherited';Expression={$Access.IsInherited}}
} 

$Files | Export-Csv "<save-path>\Folder-Permissions-$((Get-Date).ToString("yyyy-MM-dd_HHmmss")).csv" -NoTypeInformation

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top