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