How to get public folder permission with last modified date and export to csv?

Huynh, Diem 0 Reputation points

# Get public folder permissions 
$permissions = Get-PublicFolder -Recurse | Get-PublicFolderClientPermission | Select-Object Identity, User, AccessRights

# Get last modified dates for each folder
$modifiedDates = Get-PublicFolder -Recurse | ForEach-Object {
    $folderName = $_.Identity
    $lastModifiedDate = Get-PublicFolderStatistics -Identity $_.Identity | Select-Object -ExpandProperty LastModificationTime
        FolderName = $folderName
        LastModifiedDate = $lastModifiedDate

# Combine permission data with last modified date
$result = foreach ($permission in $permissions) {
    $modifiedDate = ($modifiedDates | Where-Object { $_.FolderName -eq $permission.Identity }).LastModifiedDate
    $permission | Add-Member -MemberType NoteProperty -Name LastModifiedDate -Value $modifiedDate -PassThru

# Export to CSV
$result | Export-Csv \PublicFolderPermissionsWithLastModified.csv -NoTypeInformation

Microsoft Exchange Online
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,448 questions
{count} votes