# Connect to Office 365 (remove these three lines for on-premise usage) $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session -DisableNameChecking #Change this to the email adress of your 360 Syncronize Service Account Mailbox $TSZ = "exchsync@example.com" #Change this to include the desired. Examples: #$users = Get-User -OrganizationalUnit "Sales" #$users = get-user johndoe@example.com $users = get-user $360ExchangeFolders = "^/Kalender$|^/Opgaver$|^/Calendar$|^/Tasks$" foreach ($user in $users) { Write-Host "user: $user" $mailbox = $null $mailbox = Get-mailbox -Identity $user.Identity -ErrorAction SilentlyContinue if ([bool]$mailbox) { Write-Host $mailbox.PrimarySmtpAddress $alias = $mailbox.alias; [string[]] $FolderPaths = Get-MailboxfolderStatistics $alias | % {$_.folderpath} if ([bool]$FolderPaths) { $UsableFolderPaths = $FolderPaths | where { $_ -match $360ExchangeFolders } $UsableExchangeFolderPaths = $UsableFolderPaths | % {$alias + ":" + $_.replace('/','\')} if ([bool]$UsableExchangeFolderPaths) { foreach ($folder in $UsableExchangeFolderPaths) { $folder if ([bool](get-mailboxfolderPermission $folder -User $TSZ -ErrorAction SilentlyContinue)) { Write-Host "Changing permission to: Editor" -ForegroundColor Green Set-MailboxFolderPermission -Identity $folder -User $TSZ -AccessRights Editor -WarningAction SilentlyContinue } else { Write-Host "Adding permission: Editor" -ForegroundColor Green Add-MailboxFolderPermission -Identity $folder -User $TSZ -AccessRights Editor } } } else { Write-Host "!No folders found!" -ForegroundColor Red } } } else { Write-Host "!No mailbox found!" -ForegroundColor Red } }