Forum Discussion
RE: help with powershell script please
hi i need help with a powershell script to get all the calendar permissions that a particular user has its an on prem exchange. This is my code so far. I need access rights, identity and user i need this data exported to a csv. It would be good if i could set the para to also be for a few users that im after.
Get-Mailbox | ForEach-Object { Get-MailboxFolderPermission (($_.PrimarySmtpAddress.ToString())+”:\Calendar”) -User -ErrorAction SilentlyContinue} | select-object -property @{Label='Identity,User,AccessRights'; expression={$_.accessrights -join ';'}} |Export-CSV -Path C:\Temp\user.csv -NoTypeInformation
then was told to add this via reddit :-
select-object -property @{Label='AccessRights'; expression={$_.accessrights -join ';'}
unfortunately they arent very helpful or willing to which i find is rude so im turning to this community. I just want the script i need it today please I have not got time to go backwards and forwards with different things its not hard someone must know how to format what i want. I will work out later with learning more of scripting. Right now im on a time contra
1 Reply
- MMeyer260Copper Contributor
SteveMSPI think this is what you're looking for. I don't have an Exchange server to test with.
Get-Mailbox -ResultSize Unlimited | ForEach-Object {
Get-MailboxFolderPermission (($_.PrimarySmtpAddress.ToString())+':\Calendar') -User -ErrorAction SilentlyContinue
} | select-object -property Identity,User,@{Label='AccessRights'; expression={$_.accessrights -join ';'}} |
Export-CSV -Path 'C:\Temp\user.csv' -NoTypeInformationHere is a script written by ChatGPT:
# Get a list of all mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited# Create an array to store the results
$results = @()# Loop through each mailbox
foreach ($mailbox in $mailboxes) {
# Get calendar permissions for the mailbox
$calendarPermissions = Get-MailboxFolderPermission -Identity $mailbox.UserPrincipalName":\Calendar" | Where-Object { $_.User -ne "Default" -and $_.User -ne "Anonymous" }# Loop through each calendar permission
foreach ($permission in $calendarPermissions) {
# Add mailbox name, user, and permission to results array
$result = [PSCustomObject]@{
Mailbox = $mailbox.DisplayName
User = $permission.User
Permission = $permission.AccessRights
}
$results += $result
}
}# Export results to CSV
$results | Export-Csv -Path "CalendarPermissions.csv" -NoTypeInformation