PowerShell Script needing to pull "Date Modified" on folder properties

Martin B 86 Reputation points
2022-08-26T19:55:58.65+00:00

Hi All,
I am working on a PowerShell script that needs to export to CSV file all folders that are up to 3 levels deep
The script needs to pull the permissions from the folder as well as the Last date modified of the folder.
I have the permissions and depth sorted but need to get the last date modified working and showing on the csv file.
Any help would be appreciated

Here is the script I'm using

$FolderPath = dir -Directory -Path "\fs1\Shared" -Recurse -Depth 3
$Report = @()
Foreach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder.FullName
foreach ($Access in $acl.Access)
{
$Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD
Group or
User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Report += New-Object -TypeName PSObject -Property $Properties
}
}
$Report | Export-Csv -path "C:\data\FolderPermissions.csv"

Windows for business Windows Server User experience PowerShell
{count} vote

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-08-26T20:35:29.323+00:00

    Try this:

    Get-ChildItem -Directory -Path \\fs1\Shared -Recurse -Depth 3 |  
        Foreach-Object {  
            $Acl = Get-Acl -Path $_.FullName  
            foreach ($Access in $acl.Access) {  
                $Properties = [ordered]@{  
                                            'FolderName'        = $_.FullName  
                                            'AD Group or User'  = $Access.IdentityReference  
                                            'Permissions'       = $Access.FileSystemRights  
                                            'Inherited'         = $Access.IsInherited  
                                            'LastWriteTime'     = $_.LastWriteTime  
                                        }  
                [PSCustomObject]$Properties  
            }  
        } | Export-Csv -Path "C:\data\FolderPermissions.csv"  
    
    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Martin B 86 Reputation points
    2022-08-26T21:42:58.917+00:00

    Hi Rich,
    Thank you so much for this! It's much appreciated.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.