getting users, gettings mailbox, dialog functions, error trycatch

This commit is contained in:
Jérémi N ‘EndMove’ 2022-08-25 17:27:45 +02:00
parent 6401784fbd
commit 9e41fe51ca
Signed by: EndMove
GPG Key ID: 65C4A02E1F5371A4
8 changed files with 147 additions and 40 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
access_rights_update.log

View File

@ -1,2 +1,11 @@
# EXCAL-ARIGHTS # 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

View File

@ -10,17 +10,28 @@
# @link https://git.endmove.eu/EndMove/excal-arights # @link https://git.endmove.eu/EndMove/excal-arights
#> #>
# Permission to use (define current by this one) # Availables Permission
$permission = "LimitedDetails" # - AvailabilityOnly
# - LimitedDetails
# - Reviewer
# - Editor
# Permission to use (define the triggered permission by this one)
$Permission = "LimitedDetails"
# Permissions trigger ()
$PermissionsTrigger = @("AvailabilityOnly")
# Name of the calendar folder in the user's calendar # Name of the calendar folder in the user's calendar
$calandarFolders = @("Calendar", "Calendrier", "Kalender") $CalandarFolders = @("Agenda", "Calendar", "Calendrier", "Kalender")
# Alias of account to be skipped (an alias, is the email prefix ahead of the @domain.com) # Alias of account to be skipped (an alias, is the email prefix ahead of the @domain.com)
$ignoreAlias = @("raoul.nihart", "brecht.marsoul") $IgnoreAlias = @("raoul.nihart", "brecht.marsoul")
# Email of the Administration account to use # Email of the Administration account to use
$adminAccount = "endmove@luminussolutions.be" $AdminAccount = "admin@luminussolutions.be"
# Logs file in which log all process # Logs file in which log all process
$logFile = "access_rights_update.log" $LogFile = "access_rights_update.log"
# Script name
$ScriptName = "EXCAL-ARIGHTS"

View File

@ -1,4 +0,0 @@
Get-ExecutionPolicy
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy Restricted

66
run-script.ps1 Normal file
View File

@ -0,0 +1,66 @@
<##
# 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)
. $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

26
run.ps1
View File

@ -1,26 +0,0 @@
<##
# 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)
. $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

20
utils/dev-note.txt Normal file
View File

@ -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
}
}

30
utils/functions.ps1 Normal file
View File

@ -0,0 +1,30 @@
<##
# EXCAL-ARIGHTS - utilities function
#
# @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
#>
# 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')
}