diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..695b512 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +access_rights_update.log \ No newline at end of file diff --git a/README.md b/README.md index cffc295..0e2e9c8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # EXCAL-ARIGHTS +[![Donate][link-icon-coffee]][link-paypal-me] [![Website][link-icon-website]][link-website] + +[link-icon-coffee]: https://img.shields.io/badge/%E2%98%95-Buy%20me%20a%20cup%20of%20coffee-991481.svg +[link-paypal-me]: https://www.paypal.me/EndMove/2.5eur +[link-icon-website]: https://img.shields.io/badge/%F0%9F%92%BB-My%20Web%20Site-0078D4.svg +[link-website]: https://www.endmove.eu/ + +## Description + diff --git a/configs.ps1 b/configs.ps1 index f238f5c..e0928b8 100644 --- a/configs.ps1 +++ b/configs.ps1 @@ -10,17 +10,28 @@ # @link https://git.endmove.eu/EndMove/excal-arights #> - # Permission to use (define current by this one) - $permission = "LimitedDetails" +# Availables Permission +# - AvailabilityOnly +# - LimitedDetails +# - Reviewer +# - Editor +# Permission to use (define the triggered permission by this one) +$Permission = "LimitedDetails" - # Name of the calendar folder in the user's calendar - $calandarFolders = @("Calendar", "Calendrier", "Kalender") +# Permissions trigger () +$PermissionsTrigger = @("AvailabilityOnly") - # Alias of account to be skipped (an alias, is the email prefix ahead of the @domain.com) - $ignoreAlias = @("raoul.nihart", "brecht.marsoul") +# Name of the calendar folder in the user's calendar +$CalandarFolders = @("Agenda", "Calendar", "Calendrier", "Kalender") - # Email of the Administration account to use - $adminAccount = "endmove@luminussolutions.be" +# Alias of account to be skipped (an alias, is the email prefix ahead of the @domain.com) +$IgnoreAlias = @("raoul.nihart", "brecht.marsoul") - # Logs file in which log all process - $logFile = "access_rights_update.log" \ No newline at end of file +# Email of the Administration account to use +$AdminAccount = "admin@luminussolutions.be" + +# Logs file in which log all process +$LogFile = "access_rights_update.log" + +# Script name +$ScriptName = "EXCAL-ARIGHTS" \ No newline at end of file diff --git a/dev-note.txt b/dev-note.txt deleted file mode 100644 index f573b46..0000000 --- a/dev-note.txt +++ /dev/null @@ -1,4 +0,0 @@ -Get-ExecutionPolicy - -Set-ExecutionPolicy Unrestricted -Set-ExecutionPolicy Restricted \ No newline at end of file diff --git a/run-script.ps1 b/run-script.ps1 new file mode 100644 index 0000000..52961a7 --- /dev/null +++ b/run-script.ps1 @@ -0,0 +1,66 @@ +<## + # EXCAL-ARIGHTS - runable script (entrypoint) + # + # @version 1.0.0 + # @since 08-25-2022 + # + # @author Jérémi Nihart + # @copyright © 2022 EndMove, All rights reserved. + # + # @link https://git.endmove.eu/EndMove/excal-arights + #> + +# Setup script +$Root = (Split-Path $MyInvocation.MyCommand.Path -Parent) +. $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} +Write-Host ("We found " + $Users.count + " users`n") -BackgroundColor White -ForegroundColor Black + +# 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 + + + } + } + 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 \ No newline at end of file diff --git a/run.ps1 b/run.ps1 deleted file mode 100644 index 08fdfa3..0000000 --- a/run.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -<## - # EXCAL-ARIGHTS - runable script (entrypoint) - # - # @version 1.0.0 - # @since 08-25-2022 - # - # @author Jérémi Nihart - # @copyright © 2022 EndMove, All rights reserved. - # - # @link https://git.endmove.eu/EndMove/excal-arights - #> - -# Setup script -$root = (Split-Path $MyInvocation.MyCommand.Path -Parent) -. $root\configs.ps1 -Import-Module ExchangeOnlineManagement - -# Start logging -Start-Transcript -Path $root\$logFile -Append - -# Initiate exchange connection -Connect-ExchangeOnline -UserPrincipalName $adminAccount -ShowProgress $true - - -# Stop logging -Stop-Transcript \ No newline at end of file diff --git a/utils/dev-note.txt b/utils/dev-note.txt new file mode 100644 index 0000000..988164e --- /dev/null +++ b/utils/dev-note.txt @@ -0,0 +1,20 @@ +Get-ExecutionPolicy + +Set-ExecutionPolicy Unrestricted +Set-ExecutionPolicy Restricted + +Install powershell 7 from powershell 5 : +iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI" + + +foreach ($u in $users) +{ +Write-Host $u.Name -ForegroundColor Green +$cal = Get-MailboxFolderStatistics $u.Identity -FolderScope Calendar | Where-Object {$_.Name -in @("Agenda", "Calendar", "Calendrier", "Kalender")} + +foreach ($c in $cal) +{ +Write-Output $c.Name +} + +} \ No newline at end of file diff --git a/utils/functions.ps1 b/utils/functions.ps1 new file mode 100644 index 0000000..d2f93db --- /dev/null +++ b/utils/functions.ps1 @@ -0,0 +1,30 @@ +<## + # EXCAL-ARIGHTS - utilities function + # + # @version 1.0.0 + # @since 08-25-2022 + # + # @author Jérémi Nihart + # @copyright © 2022 EndMove, All rights reserved. + # + # @link https://git.endmove.eu/EndMove/excal-arights + #> + +# Show a question dialog (yes/no) +Function DialogAsk { + param ( + [string]$Title, + [string]$Message + ) + $MsgBoxInput = [System.Windows.MessageBox]::Show($Message, $Title, 'YesNo', 'Question') + if ($MsgBoxInput -eq 'Yes') {Return $true} else {Return $false} +} + +# Show an information dialog +Function DialogSay { + param ( + [string]$Title, + [string]$Message + ) + [System.Windows.MessageBox]::Show($Message, $Title, 'OK', 'Information') +} \ No newline at end of file