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) # 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")
# 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 # Email of the Administration account to use
$AdminAccount = "admin@luminussolutions.be" $AdminAccount = "admin@luminussolutions.be"

View File

@ -12,7 +12,7 @@
# Setup script # Setup script
$Root = (Split-Path $MyInvocation.MyCommand.Path -Parent) $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\configs.ps1
. $Root\utils\functions.ps1 . $Root\utils\functions.ps1
Import-Module ExchangeOnlineManagement Import-Module ExchangeOnlineManagement
@ -22,13 +22,18 @@ Add-Type -AssemblyName PresentationFramework
Start-Transcript -Path $Root\$LogFile -Append Start-Transcript -Path $Root\$LogFile -Append
# Statistics variables # Statistics variables
$CountOK = 0 $CountUsers = 0
$CountUpdated = 0 $CountUpdates = 0
$CountError = 0 $CountErrors = 0
# Initiate exchange connection # Initiate exchange connection
Connect-ExchangeOnline -UserPrincipalName $AdminAccount -ShowProgress $true 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 ? # 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) { if ((DialogAsk "$ScriptName" "Do you want to continue and change the permission of the calendars according to your current configuration?") -eq $false) {
Stop-Transcript Stop-Transcript
@ -36,43 +41,51 @@ if ((DialogAsk "$ScriptName" "Do you want to continue and change the permission
} }
# Retrieving users mailbox # Retrieving users mailbox
$Users = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object {$_.Alias -notin $IgnoreAlias} $Users = Get-EXOMailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object {$_.Alias -notin $IgnoreAlias}
Write-Host ("[$ScriptName] We found " + $Users.count + " users`n") -BackgroundColor White -ForegroundColor Black $CountUsers = $Users.count
Write-Host ("[$ScriptName] We found $CountUsers users") -BackgroundColor White -ForegroundColor Black
# Processing users mailbox list # 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) { foreach ($User in $Users) {
Write-Host $user.Name -BackgroundColor DarkBlue Write-Host $User.Name -BackgroundColor DarkBlue
try { 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 # Process user calandars
foreach ($Calandar in $Calandars) { foreach ($Calandar in $Calandars) {
Write-Host $Calandar.Name.ToString() -BackgroundColor DarkMagenta
$CurrCalId = $User.Identity.ToString() + ":\" + $Calandar.Name.ToString() $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 # Nothing to change ?
if ($PermissionsTrigger -Contains $CurrCalPerm.AccessRights) { if ($CurrCalPerms.count -eq 0) {
Write-Host " [X] " -NoNewline Write-Host (" OK --> The permissions are in accordance with the current configuration.") -ForegroundColor Yellow
Write-Host ("Updated : The permission has been updated from (" + $CurrCalPerm.AccessRights + ") to (" + $Permission + ").") -ForegroundColor Green }
$CountOK++
# 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) # Update permission (for debugging: -WhatIf)
Set-MailboxFolderPermission -Identity $CurrCalId -User Default -AccessRights $Permission Set-MailboxFolderPermission -Identity $CurrCalId -User $CurrCalPerm.User.ToString() -AccessRights $Permission -WhatIf
} else { $CountLocalUpdates++
Write-Host " [X] " -NoNewline
Write-Host ("Ignored : The permission (" + $CurrCalPerm.AccessRights + ") of this user did not launch the trigger.") -ForegroundColor Yellow
$CountUpdated++
} }
} }
Write-Host ("($CountLocalUpdates permissions updated for $CurrCalId)") -BackgroundColor White -ForegroundColor Black
$CountUpdates += $CountLocalUpdates
} }
catch { catch {
Write-Host "[ERROR] An unexpected error occured." -ForegroundColor DarkRed Write-Host "[ERROR] An unexpected error occured." -ForegroundColor DarkRed
Write-Host "--> $_" -ForegroundColor DarkRed Write-Host "--> $_" -ForegroundColor DarkRed
$CountError++ $CountErrors++
} }
Write-Host Write-Host
} }
# Showing resultats # 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 logging
Stop-Transcript Stop-Transcript

View File

@ -1,4 +1,6 @@
Get-ExecutionPolicy Get-ExecutionPolicy
Set-ExecutionPolicy Unrestricted 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 [string]$Message
) )
[System.Windows.MessageBox]::Show($Message, $Title, 'OK', 'Information') [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
}
} }