Thursday, August 4, 2016

Powershell - Show Shared Exchange Calendars

So, for a little bit of back story on this, one of the problems we are running into here, is that when people leave, their Exchange accounts are removed. Many of them have calendars for rooms, appointments, or other business related Calendars that they have shared out from their account.

I wrote this to help identify where these calendars were, and who had access to them. Hopefully it can be of use to somebody else out there.



$mailboxes = Get-mailbox -ResultSize Unlimited
$sharedCalendars = $mailboxes.alias | % {Get-MailboxFolderStatistics $_ | Where-Object {$_.FolderType -eq 'User Created' -and $_.folderpath -like '/calendar/*'} }

$sharedCalendars | % {
$_ | Add-Member -MemberType NoteProperty -Name ExIdentity -value ($_.identity -replace '^(.*?)\\(.*)','$1:\$2')
return $_
} | % {
    $ident = $_.Identity
    $ex = $_.ExIdentity
    Write-Host -Foreground Cyan "Permissions for $ident"
    $perms = Get-MailboxFolderPermission -Identity $ex
    $perms | ft
    $_ | Add-Member -MemberType NoteProperty -Name PermList -Value ($perms | Select User, AccessRights)
}
#now show some stuff!
$sharedCalendars | % {
    $name = $_.Name
    $identity = $_.ExIdentity
    Write-Host -Foreground Cyan "Calendar: $Name"
    Write-Host "Identity: $identity"
    $_.PermList | % {
        $user = $_.User
        $rights = $_.AccessRights
        Write-Host "`t$user`t$rights"
       
    }
}




You will need to run this on the Exchange Management shell or already be connected to exchange via powershell. Run this first if the above code doesn't work out of the box. 


$credential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeServer/PowerShell/ -Credential $credential
Import-PSSession $Session -AllowClobber -DisableNameChecking

No comments:

Post a Comment