Get-CalendarPermissionsReport.ps1


Description

@GitHub Copilot - Welcome @BanterBoy, I’m your Copilot and I’m here to help you get things done faster. I can identify issues, explain and even improve code.

You can ask generic questions, but what I’m really good at is helping you with your code. For example:

Generate unit tests for my code Explain the selected code Propose a fix for the bugs in my code If you want to learn more about my capabilities and limitations, check out the Copilot documentation.

I’m powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

@BanterBoy: - Explain what the script does and why it is useful.

@GitHub Copilot -


Script

<#
.SYNOPSIS
PowerShell script to get Exchange Calendar permissions report.

.DESCRIPTION
The script gets Calendar permissions report within your Exchange organization. It also can get a report from Office 365.

.PARAMETER Version
Mandatory parameter. Select between Exchange Versions. It can be 2010, 2013-2016 or O365.

.PARAMETER File
Optional parameter. Exports the results to file.

.EXAMPLE
.\Get-CalendarPermissionsReport.ps1 -Version 2010 -File FileName.csv
Gets calendar permissions report for Exchange 2010 and exports the results to FileName.csv file.

.EXAMPLE
.\Get-CalendarPermissionsReport.ps1 -Version 2013-2016 -File FileName.csv
Gets calendar permissions report for Exchange 2013 or 2016 and exports the results to FileName.csv file.

.EXAMPLE
 .\Get-CalendarPermissionsReport.ps1 -Version O365 -File FileName.csv
Gets calendar permissions report for Exchange Online and exports the results to FileName.csv file. It will ask an Office 365 admin credentials.

.EXAMPLE
.\Get-CalendarPermissionsReport.ps1 -Version O365
Connects to Exchange Online and prints calendar permissions to console.

.LINK
Script author Slava Fedenko - http://blog.fedenko.info
#>

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $True)]
    [ValidateSet('2010', '2013-2016', 'O365')]
    [String]$Version,

    [Parameter(Mandatory = $False)]
    [ValidateNotNull()]
    [String]$File

)

if ($Version -like "2010") {
    $Out = @()
    $mbxs = Get-Mailbox | Where-Object { $_.WindowsEmailAddress -like '*pepcoservices*' }
    foreach ($mbx in $mbxs) {
        $id = $mbx.alias
        $id = $id + ":\Calendar"
        $perms = Get-MailboxFolderPermission -Identity $id | Where-Object { $_.User -notlike "Anonymous" -and $_.User -notlike "Default" }
        foreach ($perm in $perms) {
            if (!$perm) { break }
            $Properties = @{
                "Mailbox"      = $mbx.DisplayName;
                "Email"        = $mbx.windowsemailaddress;
                "User"         = $perm.User;
                "AccessRights" = $perm.AccessRights -join ','
            }
            $Obj = New-Object -TypeName PSObject -Property $Properties

            if (!$File) {
                Write-Output $Obj | Select-Object Mailbox, Email, User, AccessRights
            }
            $Out += $Obj
        }

    }
    if ($File) {
        $Out | Select-Object Mailbox, Email, User, AccessRights | Export-Csv -NoTypeInformation $File
    }
}


if ($Version -like "2013-2016") {
    if (!$File) {
        Get-Mailbox | ForEach-Object { Get-MailboxFolderPermission -Identity "$($_.alias):\Calendar" | Where-Object { $_.User -notlike "Anonymous" -and $_.User -notlike "Default" } } | Select-Object Identity, User, @{name = 'AccessRights'; expression = { $_.AccessRights -join ',' } }
    }
    if ($File) {
        Get-Mailbox | ForEach-Object { Get-MailboxFolderPermission -Identity "$($_.alias):\Calendar" | Where-Object { $_.User -notlike "Anonymous" -and $_.User -notlike "Default" } } | Select-Object Identity, User, @{name = 'AccessRights'; expression = { $_.AccessRights -join ',' } } | Export-Csv -NoTypeInformation $File
    }
}

if ($Version -like "O365") {
    $UserCredential = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
    Import-PSSession $Session

    if (!$File) {
        Get-Mailbox | ForEach-Object { Get-MailboxFolderPermission -Identity "$($_.alias):\Calendar" | Where-Object { $_.User -notlike "Anonymous" -and $_.User -notlike "Default" } } | Select-Object Identity, User, @{name = 'AccessRights'; expression = { $_.AccessRights -join ',' } }
    }
    if ($file) {
        Get-Mailbox | ForEach-Object { Get-MailboxFolderPermission -Identity "$($_.alias):\Calendar" | Where-Object { $_.User -notlike "Anonymous" -and $_.User -notlike "Default" } } | Select-Object Identity, User, @{name = 'AccessRights'; expression = { $_.AccessRights -join ',' } } | Export-Csv -NoTypeInformation $File
    }
    Remove-PSSession $Session
}

Back to Top


Download

Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top