Script GUI de modification des autorisations de boîte aux lettres Exchange 2013

Ce script que j’ai réalisé avec l’aide de Primal Forms peut être utilisé pour modifier les autorisations de boîte aux lettres. Vous pouvez utiliser ce script pour ajouter ou supprimer des permissions de boîte aux lettres Microsoft Exchange 2013.

Ce script fournit une interface utilisateur graphique (GUI). Vous pouvez utiliser ce script de la manière suivante:
1.Téléchargez le script et le copier sur un serveur Exchange ou avec un accès Powershell distant.
2.Exécutez le script dans une console Exchange Management Shell

Gui Mailbox Rights: MailboxRightsGUI.ps1

 GuiMailboxRights

Code PowerShell:

#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 24/08/2014 19:41
# Generated By: Cédric Beys
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(« System.Drawing ») | Out-Null
[reflection.assembly]::loadwithpartialname(« System.Windows.Forms ») | Out-Null
#endregion

Function Add-RightsMailbox {
If ($FullCheckBox1.Checked -eq $true){
Add-MailboxPermission -Identity $TargetBox2.text -User $SourceBox1.text -Accessright Fullaccess,DeleteItem,ReadPermission,ChangePermission,ChangeOwner -InheritanceType all | fl
}
If ($SendCheckBox2.Checked -eq $true){
Set-Mailbox $TargetBox2.text -GrantSendOnBehalfTo $SourceBox1.text
Add-ADPermission $TargetBox2.text -User $SourceBox1.text -ExtendedRights Send-As | fl
}

If (($SourceBox1.Text -ne « Select Mailbox ») -and ($TargetBox2.Text -ne « Select Mailbox »))
{
[Windows.Forms.MessageBox]::Show(“Add Mailbox Permissions Successful.”, “Success”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
}
Else
{
[Windows.Forms.MessageBox]::Show(“Add Mailbox Permissions Failed. To see what went wrong check the powershell window.”, “Error”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Error)
}
}

Function Del-RightsMailbox {
If ($FullCheckBox1.Checked -eq $true){
Remove-MailboxPermission -Identity $TargetBox2.text -User $SourceBox1.text -Accessright Fullaccess,DeleteItem,ReadPermission,ChangePermission,ChangeOwner -InheritanceType all -Confirm: $False | fl
}
If ($SendCheckBox2.Checked -eq $true){
Set-Mailbox $TargetBox2.text -GrantSendOnBehalfTo $null
Remove-ADPermission $TargetBox2.text -User $SourceBox1.text -ExtendedRights Send-As -Confirm: $False| fl
}

If (($SourceBox1.Text -ne « Select Mailbox ») -and ($TargetBox2.Text -ne « Select Mailbox »))
{
[Windows.Forms.MessageBox]::Show(“Remove Mailbox Permissions Successful.”, “Success”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
}
Else
{
[Windows.Forms.MessageBox]::Show(“Remove Mailbox Permissions Failed. To see what went wrong check the powershell window.”, “Error”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Error)
}
}

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$ResetButton3 = New-Object System.Windows.Forms.Button
$DelButton2 = New-Object System.Windows.Forms.Button
$AddButton1 = New-Object System.Windows.Forms.Button
$label2 = New-Object System.Windows.Forms.Label
$label1 = New-Object System.Windows.Forms.Label
$TargetBox2 = New-Object System.Windows.Forms.ComboBox
$SourceBox1 = New-Object System.Windows.Forms.ComboBox
$panel1 = New-Object System.Windows.Forms.Panel
$label3 = New-Object System.Windows.Forms.Label
$SendCheckBox2 = New-Object System.Windows.Forms.CheckBox
$FullCheckBox1 = New-Object System.Windows.Forms.CheckBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState

$SourceBox1.Text = « Select Mailbox »
Get-Mailbox | ForEach-Object {$SourceBox1.Items.Add($_.DisplayName)}

$TargetBox2.Text = « Select Mailbox »
Get-Mailbox | ForEach-Object {$TargetBox2.Items.Add($_.DisplayName)}
#endregion Generated Form Objects

#———————————————-
#Generated Event Script Blocks
#———————————————-
#Provide Custom Code for events specified in PrimalForms.
$ResetButton3_OnClick=
{
#TODO: Place custom script here
$SourceBox1.Text = « Select Mailbox »
$TargetBox2.Text = « Select Mailbox »
$FullCheckBox1.Checked = «  »
$SendCheckBox2.Checked = «  »
}

$AddButton1_OnClick=
{
#TODO: Place custom script here
Add-RightsMailbox
}

$DelButton2_OnClick=
{
#TODO: Place custom script here
Del-RightsMailbox
}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}

#———————————————-
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 282
$System_Drawing_Size.Width = 391
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = « form1 »
$form1.Text = « Mailbox Rights for Exchange 2013 v1.0 »
$ResetButton3.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 295
$System_Drawing_Point.Y = 238
$ResetButton3.Location = $System_Drawing_Point
$ResetButton3.Name = « ResetButton3 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$ResetButton3.Size = $System_Drawing_Size
$ResetButton3.TabIndex = 10
$ResetButton3.Text = « Reset »
$ResetButton3.UseVisualStyleBackColor = $True
$ResetButton3.add_Click($ResetButton3_OnClick)

$form1.Controls.Add($ResetButton3)
$DelButton2.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 182
$System_Drawing_Point.Y = 238
$DelButton2.Location = $System_Drawing_Point
$DelButton2.Name = « DelButton2 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 60
$DelButton2.Size = $System_Drawing_Size
$DelButton2.TabIndex = 9
$DelButton2.Text = « Del »
$DelButton2.UseVisualStyleBackColor = $True
$DelButton2.add_Click($DelButton2_OnClick)

$form1.Controls.Add($DelButton2)
$AddButton1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 80
$System_Drawing_Point.Y = 238
$AddButton1.Location = $System_Drawing_Point
$AddButton1.Name = « AddButton1 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 67
$AddButton1.Size = $System_Drawing_Size
$AddButton1.TabIndex = 8
$AddButton1.Text = « Add »
$AddButton1.UseVisualStyleBackColor = $True
$AddButton1.add_Click($AddButton1_OnClick)

$form1.Controls.Add($AddButton1)

$label2.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 62
$label2.Location = $System_Drawing_Point
$label2.Name = « label2 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 87
$label2.Size = $System_Drawing_Size
$label2.TabIndex = 3
$label2.Text = « Target Mailbox »

$form1.Controls.Add($label2)

$label1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 29
$label1.Location = $System_Drawing_Point
$label1.Name = « label1 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 87
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 2
$label1.Text = « Source Mailbox »

$form1.Controls.Add($label1)

$TargetBox2.DataBindings.DefaultDataSourceUpdateMode = 0
$TargetBox2.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 109
$System_Drawing_Point.Y = 62
$TargetBox2.Location = $System_Drawing_Point
$TargetBox2.Name = « TargetBox2 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 21
$System_Drawing_Size.Width = 149
$TargetBox2.Size = $System_Drawing_Size
$TargetBox2.TabIndex = 1

$form1.Controls.Add($TargetBox2)

$SourceBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$SourceBox1.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 109
$System_Drawing_Point.Y = 26
$SourceBox1.Location = $System_Drawing_Point
$SourceBox1.Name = « SourceBox1 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 21
$System_Drawing_Size.Width = 149
$SourceBox1.Size = $System_Drawing_Size
$SourceBox1.TabIndex = 0

$form1.Controls.Add($SourceBox1)
$panel1.BorderStyle = 2
$panel1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 67
$System_Drawing_Point.Y = 121
$panel1.Location = $System_Drawing_Point
$panel1.Name = « panel1 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 111
$System_Drawing_Size.Width = 191
$panel1.Size = $System_Drawing_Size
$panel1.TabIndex = 7

$form1.Controls.Add($panel1)
$label3.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 20
$System_Drawing_Point.Y = 7
$label3.Location = $System_Drawing_Point
$label3.Name = « label3 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 103
$label3.Size = $System_Drawing_Size
$label3.TabIndex = 4
$label3.Text = « Add or delete Mailbox Permission »

$panel1.Controls.Add($label3)
$SendCheckBox2.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 40
$System_Drawing_Point.Y = 80
$SendCheckBox2.Location = $System_Drawing_Point
$SendCheckBox2.Name = « SendCheckBox2 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 24
$System_Drawing_Size.Width = 104
$SendCheckBox2.Size = $System_Drawing_Size
$SendCheckBox2.TabIndex = 6
$SendCheckBox2.Text = « Send As »
$SendCheckBox2.UseVisualStyleBackColor = $True

$panel1.Controls.Add($SendCheckBox2)
$FullCheckBox1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 40
$System_Drawing_Point.Y = 50
$FullCheckBox1.Location = $System_Drawing_Point
$FullCheckBox1.Name = « FullCheckBox1 »
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 24
$System_Drawing_Size.Width = 104
$FullCheckBox1.Size = $System_Drawing_Size
$FullCheckBox1.TabIndex = 5
$FullCheckBox1.Text = « Full Access »
$FullCheckBox1.UseVisualStyleBackColor = $True

$panel1.Controls.Add($FullCheckBox1)
#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l’aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Google

Vous commentez à l’aide de votre compte Google. Déconnexion /  Changer )

Image Twitter

Vous commentez à l’aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s