Début transition vers protocol exchange v2 + correction de bug + mis en place deep search

This commit is contained in:
Jérémi N ‘EndMove’ 2022-08-25 23:26:12 +02:00
parent 1867106799
commit 2e4b8a4525
Signed by: EndMove
GPG Key ID: 65C4A02E1F5371A4
4 changed files with 63 additions and 22 deletions

View File

@ -27,6 +27,9 @@ $CalandarFolders = @("Agenda", "Calendar", "Calendrier", "Kalender")
# Alias of account to be skipped (an alias, is the email prefix ahead of the @domain.com)
$IgnoreAlias = @("raoul.nihart", "brecht.marsoul")
# Name of account to be skipped when permission for it's is set into user's calandar (a full name ex: Jeremi Nihart)
$IgnoreUsers = @("Anonymous")
# Email of the Administration account to use
$AdminAccount = "admin@luminussolutions.be"

View File

@ -12,7 +12,7 @@
# Setup script
$Root = (Split-Path $MyInvocation.MyCommand.Path -Parent)
$time = (Get-Date -Format "MM-dd-yyyy-HH-mm-ss")
$Time = (Get-Date -Format "MM-dd-yyyy-HH-mm-ss")
. $Root\configs.ps1
. $Root\utils\functions.ps1
Import-Module ExchangeOnlineManagement
@ -22,13 +22,18 @@ Add-Type -AssemblyName PresentationFramework
Start-Transcript -Path $Root\$LogFile -Append
# Statistics variables
$CountOK = 0
$CountUpdated = 0
$CountError = 0
$CountUsers = 0
$CountUpdates = 0
$CountErrors = 0
# Initiate exchange connection
Connect-ExchangeOnline -UserPrincipalName $AdminAccount -ShowProgress $true
# Do you want to preview current permissions ?
if ((DialogAsk "$ScriptName" "Do you want to preview all calandar permissions ?") -eq $true) {
DisplayAll $CalandarFolders
}
# 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
@ -36,43 +41,51 @@ if ((DialogAsk "$ScriptName" "Do you want to continue and change the permission
}
# Retrieving users mailbox
$Users = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object {$_.Alias -notin $IgnoreAlias}
Write-Host ("[$ScriptName] We found " + $Users.count + " users`n") -BackgroundColor White -ForegroundColor Black
$Users = Get-EXOMailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object {$_.Alias -notin $IgnoreAlias}
$CountUsers = $Users.count
Write-Host ("[$ScriptName] We found $CountUsers users") -BackgroundColor White -ForegroundColor Black
# Processing users mailbox list
# Info: all these loops are here because we want to follow up as we
# process the data (too much symplification is not always a good thing).
foreach ($User in $Users) {
Write-Host $user.Name -BackgroundColor DarkBlue
Write-Host $User.Name -BackgroundColor DarkBlue
try {
$Calandars = Get-MailboxFolderStatistics $User.Identity -FolderScope Calendar | Where-Object {$_.Name -in $CalandarFolders}
$Calandars = Get-EXOMailboxFolderStatistics $User.Identity -FolderScope Calendar | Where-Object {$_.Name -in $CalandarFolders}
# Process user calandars
foreach ($Calandar in $Calandars) {
Write-Host $Calandar.Name.ToString() -BackgroundColor DarkMagenta
$CurrCalId = $User.Identity.ToString() + ":\" + $Calandar.Name.ToString()
$CurrCalPerm = Get-MailboxFolderPermission -Identity $CurrCalId -User Default
$CurrCalPerms = Get-MailboxFolderPermission -Identity $CurrCalId | Where-Object {$_.Name -notin $IgnoreUsers -and $_.AccessRights -in $PermissionsTrigger}
$CountLocalUpdates = 0
# 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++
# Nothing to change ?
if ($CurrCalPerms.count -eq 0) {
Write-Host (" OK --> The permissions are in accordance with the current configuration.") -ForegroundColor Yellow
}
# Process caladar permissions
foreach ($CurrCalPerm in $CurrCalPerms) {
Write-Host (" UPDATE --> Permission for " + $CurrCalPerm.User.ToString() + " has been switch from " + $CurrCalPerm.AccessRights + " to " + $Permission + ".") -ForegroundColor Green
# Update permission (for debugging: -WhatIf)
Set-MailboxFolderPermission -Identity $CurrCalId -User Default -AccessRights $Permission
} else {
Write-Host " [X] " -NoNewline
Write-Host ("Ignored : The permission (" + $CurrCalPerm.AccessRights + ") of this user did not launch the trigger.") -ForegroundColor Yellow
$CountUpdated++
Set-MailboxFolderPermission -Identity $CurrCalId -User $CurrCalPerm.User.ToString() -AccessRights $Permission -WhatIf
$CountLocalUpdates++
}
}
Write-Host ("($CountLocalUpdates permissions updated for $CurrCalId)") -BackgroundColor White -ForegroundColor Black
$CountUpdates += $CountLocalUpdates
}
catch {
Write-Host "[ERROR] An unexpected error occured." -ForegroundColor DarkRed
Write-Host "--> $_" -ForegroundColor DarkRed
$CountError++
$CountErrors++
}
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."
DialogSay "$ScriptName" "The update was performed successfuly.`n`n$CountUpdates has been updated on $CountUsers`n$CountErrors errors occured."
# Stop logging
Stop-Transcript

View File

@ -1,4 +1,6 @@
Get-ExecutionPolicy
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy Restricted
Set-ExecutionPolicy Restricted
un objet | Get-Member -MemberType Property

View File

@ -27,4 +27,27 @@ Function DialogSay {
[string]$Message
)
[System.Windows.MessageBox]::Show($Message, $Title, 'OK', 'Information')
}
# Show current permissions for all calandars and users
Function DisplayAll {
param (
[string[]]$CalandarFolders
)
$Users = Get-EXOMailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox
Write-Host ("[$ScriptName] We found " + $Users.count + " users") -BackgroundColor White -ForegroundColor Black
foreach ($User in $Users) {
Write-Host $User.Name -BackgroundColor DarkGreen
$Calandars = Get-EXOMailboxFolderStatistics $User.Identity -FolderScope Calendar | Where-Object {$_.Name -in $CalandarFolders}
foreach ($Calandar in $Calandars) {
Write-Host $Calandar.Name.ToString() -BackgroundColor DarkMagenta
$CurrCalId = $User.Identity.ToString() + ":\" + $Calandar.Name.ToString()
$CurrCalPerms = Get-MailboxFolderPermission -Identity $CurrCalId
foreach ($CurrCalPerm in $CurrCalPerms) {
Write-Host ($CurrCalPerm.User.ToString() +" : " + $CurrCalPerm.AccessRights)
}
}
Write-Host
}
}