Want to output Get-MailboxFolderPermission to csv

I am working on a PS script to get Calendar permissions for specific groups, and I’m having trouble getting the output formatted for csv/xlsx. It’s been a while since I’ve used PS regularly, so I’m a bit rusty. I have the output stored in an object, and it all looks fine on the screen, but I’m having trouble iterating through the results. I want to have each Identity listed, then show each User who has permission to the calendar, along with their AccessRights and thd SharingPermissionFlags. I tried a nested foreach loop, with the outer loop for each Identity, then another foreach loop for the User who has rights to the calendar. Here is what I have so far:

$tblMembers = Import-Csv 'C:\Users\BPE8345\Documents\My PS Projects\TBL_Members.csv'
$outputFile = 'C:\Users\BPE8345\Documents\My PS Projects\TBL_Members_Calendar_Permissions.csv'
$calendarPermissionList = @()
$tempCalendarUser = @()

foreach ($tblUser in $tblMembers)
{
    $identity = $tblUser.Identity
    $calendarPermission = Get-MailboxFolderPermission $identity':\Calendar' | ? {$_.User -notlike "Default"} | select User, AccessRights, SharingPermissionFlags
    foreach($calendarUser in $calendarPermission)
    {
        $tempCalendarUser = New-Object psobject
        $tempCalendarUser | Add-Member -MemberType NoteProperty DisplayName -Value $tblUser.DisplayName
        $tempCalendarUser | Add-Member -MemberType NoteProperty UserWithAccess -Value $calendarUser.User
        $tempCalendarUser | Add-Member -MemberType NoteProperty AccessRights -Value $calendarUser.AccessRights
        $tempCalendarUser | Add-Member -MemberType NoteProperty SharingPermissionFlags -Value $calendarUser.SharingPermissionFlags
        $tempCalendarUser | Export-Csv $outputFile -Append -NoTypeInformation
    }
    $temp = New-Object psobject

    $temp | Add-Member -MemberType NoteProperty -Name BUDID -Value $identity
    $temp | Add-Member -MemberType NoteProperty -Name DisplayName -Value $tblUser.DisplayName
    $temp | Add-Member -MemberType NoteProperty -Name UsersWithAccess -Value $calendarPermission.User
    $temp | Add-Member -MemberType NoteProperty -Name AccessRights -Value $calendarPermission.AccessRights

    $calendarPermissionList += $temp
}

$calendarPermissionList | Export-Csv $outputFile -NoTypeInformation

I stepped through the code and I can see the data in the CalendarPermission object, and while I though writing each row to the csv would work, it isn’t. It is not showing the DisplayName attribute in the CSV file. It shows the UserWithAccess, AccessRights and the SharingPermissionFlags attributes, but since it isn’t showing the DisplayName attribute, you can’t tell whose calendar the UserWithAccess has access to. I’m sure it’s something simple, but I’m not seeing it. Any help is greatly appreciated.

Brian

Your select throws it away - it only returns three properties. You don’t really need the select in this case, so just remove it.

I don’t have an Exchange environment to test, but this should work. You are appending to an existing csv file in your nested loop, but overwriting the same csv file at the end of your code. Tips: No need for nested loops or aliases. Use full cmdlets – easier to troubleshoot and the next person will thank you for it. No need to create new objects, use calculated properties.

$tblMembers = Import-Csv 'C:\Users\BPE8345\Documents\My PS Projects\TBL_Members.csv'
$outputFile = 'C:\Users\BPE8345\Documents\My PS Projects\TBL_Members_Calendar_Permissions.csv'

$result = 
foreach ($tblUser in $tblMembers)
{
    Get-MailboxFolderPermission "$($tblUser.Identity):\Calendar" | 
    Where-Object {$_.User -notlike "Default"} | 
    Select-Object @{n='DisplayName';exp={$tblUser.DisplayName}},
    @{n='BUDID';exp={$tblUser.Identity}},User,AccessRights,SharingPermissionFlags   
}

$result | Export-Csv $outputFile -NoTypeInformation

Thanks for the suggestions. I just used “select *”, and that seemed to work. I knew it was something simple.