I guess many of you who are reading my blog are also working in the Messaging and/or Cloud area. That means that you also perform Exchange migrations or you are planning them. Earlier this week I was running a clean up after an Exchange migration and I have noticed many Mailboxes with “AvailableOnly” or “none” Calendar Permissions.

This happened already few times in the last couple of months with some few Mailbox calendar permissions.

 

So how to fix that in an easy way?

Of course I want to use PowerShell to fix that small issue. However, I also had to think about the region I am coming from. Here in Switzerland we have four spoken languages (German, Italian, French and Romanic) and also English. The Company area I had the migration is located in German speaking part. That means that the language settings for Outlook are in English or in German.

Why this is important to know? Well, for English profiles we can use the PowerShell parameter :\Calendar, but by German profiles we talk about :\Kalender. I we don’t think about this point, our PowerShell script will fail.

 

Let us have a look on the script. I will present you the script below with explanations commented in it:

# Get all Mailboxes
$allMBs = Get-Mailbox

# Help Variable for getting the History
$temp = @()
# Start Script
foreach ($MB in $allMBs)
{
$Alias = $MB.Alias
    # Ignore DiscoveryMailbox
    if ($Alias -notlike "Discovery*")
    {
        # Read Calendar Permissions
        # English Langue of the Calender Name
        $Identity = $Alias + ':\Calendar'
        # Control if english Langue
        $Export = Get-MailboxFolderPermission -Identity $Identity
        if($Export){
        # If not english then in this example german
        }else{
            $Identity = $Alias + ':\Kalender'
            $Export = Get-MailboxFolderPermission -Identity $Identity
                }

# Analyse the permisson
$Export | % {
# If "None" or "AvailabilityOnly" 
if (($_.AccessRights -like "None") -or ($_.AccessRights -like "AvailabilityOnly")){
# If Default or Anonymous then do nothing
if(($_.User -like "Default") -or ($_.User -like "Anonymous")){
# None
# or remove
}else{
$Convert = $_.User
$temp += "Bei $Alias wurde der User $Convert entfernt."
Remove-MailboxFolderPermission -Identity $Identity -User $Convert -Confirm:$False
                }
            }
        }
    }
}

$temp

After running the script, we have identified all mailboxes which had the access right “AvailableOnly” or “none” (except the discovery mailbox). Then we have removed all users who had the permissions we have filtered.

Alternative we can use this script of course with other permission parameters.

 

As I have written earlier in this article, I am living and working in a country with multiple languages. If you want to modify the language settings for your region, also feel free.

However, there is also another option you can modify the script by using the following code:

 

{$AddPath = ":\" + (Get-MailboxFolderStatistics $SUser.SamAccountname | Where-Object { $_.Foldertype -eq "Calendar" } | Select-Object -First 1).Name}

 

With this you don’t have to think about the language settings anymore.