2022-08-25 17:27:45 +02:00
<# #
# EXCAL-ARIGHTS - runable script (entrypoint)
#
# @version 1.0.0
# @since 08-25-2022
#
# @author Jérémi Nihart <contact@endmove.eu>
# @copyright © 2022 EndMove, All rights reserved.
#
# @link https://git.endmove.eu/EndMove/excal-arights
#>
# Setup script
$Root = ( Split-Path $MyInvocation . MyCommand . Path -Parent )
2022-08-25 18:17:55 +02:00
$time = ( Get-Date -Format " MM-dd-yyyy-HH-mm-ss " )
2022-08-25 17:27:45 +02:00
. $Root \ configs . ps1
. $Root \ utils \ functions . ps1
Import-Module ExchangeOnlineManagement
Add-Type -AssemblyName PresentationFramework
# Start logging
Start-Transcript -Path $Root \ $LogFile -Append
# Statistics variables
$CountOK = 0
$CountUpdated = 0
$CountError = 0
# Initiate exchange connection
Connect-ExchangeOnline -UserPrincipalName $AdminAccount -ShowProgress $true
# Do you realy want to change permissions ?
if ( ( DialogAsk " $ScriptName " " Do you want to continue and change the permission of the calendars according to your current configuration? " ) -eq $false ) {
Stop-Transcript
Exit
}
# Retrieving users mailbox
$Users = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object { $_ . Alias -notin $IgnoreAlias }
2022-08-25 18:17:55 +02:00
Write-Host ( " [ $ScriptName ] We found " + $Users . count + " users `n " ) -BackgroundColor White -ForegroundColor Black
2022-08-25 17:27:45 +02:00
# Processing users mailbox list
foreach ( $User in $Users ) {
Write-Host $user . Name -BackgroundColor DarkBlue
try {
$Calandars = Get-MailboxFolderStatistics $User . Identity -FolderScope Calendar | Where-Object { $_ . Name -in $CalandarFolders }
# Process user calandars
foreach ( $Calandar in $Calandars ) {
$CurrCalId = $User . Identity . ToString ( ) + " :\ " + $Calandar . Name . ToString ( )
$CurrCalPerm = Get-MailboxFolderPermission -Identity $CurrCalId -User Default
2022-08-25 18:17:55 +02:00
# Check and update permission
if ( $PermissionsTrigger -Contains $CurrCalPerm . AccessRights ) {
Write-Host " [X] " -NoNewline
Write-Host ( " Updated : The permission has been updated from ( " + $CurrCalPerm . AccessRights + " ) to ( " + $Permission + " ). " ) -ForegroundColor Green
$CountOK + +
# Update permission
Set-MailboxFolderPermission -Identity $CurrCalId -User Default -AccessRights $Permission -WhatIf
} else {
Write-Host " [X] " -NoNewline
Write-Host ( " Ignored : The permission ( " + $CurrCalPerm . AccessRights + " ) of this user did not launch the trigger. " ) -ForegroundColor Yellow
$CountUpdated + +
}
2022-08-25 17:27:45 +02:00
}
}
catch {
Write-Host " [ERROR] An unexpected error occured. " -ForegroundColor DarkRed
Write-Host " --> $_ " -ForegroundColor DarkRed
$CountError + +
}
Write-Host
}
# Showing resultats
DialogSay " $ScriptName " " The update was performed successfuly. `n `n $CountOK account(s) was already correctly configured. `n $CountUpdated account(s) were updated. `n $CountError error(s) occurred. "
# Stop logging
Stop-Transcript