Création multiple de boîtes aux lettres
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
do {
$vUserID = [Microsoft.VisualBasic.Interaction]::InputBox("Introduisez le compte utilisateur`n`nCliquer cancel pour arrêter", "CreateMultipleUsersMailboxes", "")
if ($vUserID -ne "") {
$vUser = Get-User -Identity $vUserID
if ($vUser.RecipientTypeDetails -ne "User") {
[System.Windows.Forms.MessageBox]::Show(
"$vUserId n'est pas un utilisateur valide",
"Erreur",
[System.Windows.Forms.MessageBoxButtons]::Ok,
[System.Windows.Forms.MessageBoxIcon]::Warning,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
)
}
else
{
Enable-Mailbox -Identity $vUser.name -Alias $vUser.SamAccountName
$vMail = (Get-Mailbox -Identity $vUser.name).UserPrincipalName
[System.Windows.Forms.MessageBox]::Show(
"$vMail a été activé",
"Nouvelle boite",
[System.Windows.Forms.MessageBoxButtons]::Ok,
[System.Windows.Forms.MessageBoxIcon]::Warning,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
)
}
}
} until ($vUserID -eq "")
Création de boîtes aux lettres pour une OU
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
do {
$vOuID = [Microsoft.VisualBasic.Interaction]::InputBox("Introduisez l'organisation unit (OU)`nexemple: edu.fr.ch/FRI-TIC/Users/_test`n`nCliquer cancel pour arrêter", "CreateMailboxesInOU", "")
if ($vOuID -ne "") {
$vUserList = Get-User -OrganizationalUnit $vOuID -RecipientTypeDetails User
Get-User -OrganizationalUnit $vOuID -RecipientTypeDetails User | Format-table -AutoSize Name,SamAccountName
$vYes=[System.Windows.Forms.MessageBox]::Show(
"Les utilisateurs listés dans la fenêtre powershell vont avoir une boîte aux lettres activée",
"Activation de boîte aux lettres",
[System.Windows.Forms.MessageBoxButtons]::YesNo,
[System.Windows.Forms.MessageBoxIcon]::Question,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
)
if ($vYes -eq [Windows.Forms.DialogResult]::Yes) {
foreach ($user in $vUserList)
{
$vUserString=$vUserString + $user.SamAccountName + "`r"
Enable-Mailbox -Identity $user.name -Alias $user.SamAccountName
}
[System.Windows.Forms.MessageBox]::Show(
"Les mailboxs ont été activées pour l'OU $vOuID",
"Activation de mailbox",
[System.Windows.Forms.MessageBoxButtons]::Ok,
[System.Windows.Forms.MessageBoxIcon]::Warning,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
)
}
}
} until ($vOuID -eq "")
do {
$vOuID = [Microsoft.VisualBasic.Interaction]::InputBox("Introduisez l'organisation unit (OU)`nexemple: edu.fr.ch/FRI-TIC/Users/_test`n`nCliquer cancel pour arrêter", "CreateMailboxesInOU", "")
if ($vOuID -ne "") {
$vUserList = Get-User -OrganizationalUnit $vOuID -RecipientTypeDetails User
Get-User -OrganizationalUnit $vOuID -RecipientTypeDetails User | Format-table -AutoSize Name,SamAccountName
$vYes=[System.Windows.Forms.MessageBox]::Show(
"Les utilisateurs listés dans la fenêtre powershell vont avoir une boîte aux lettres activée",
"Activation de boîte aux lettres",
[System.Windows.Forms.MessageBoxButtons]::YesNo,
[System.Windows.Forms.MessageBoxIcon]::Question,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
)
if ($vYes -eq [Windows.Forms.DialogResult]::Yes) {
foreach ($user in $vUserList)
{
$vUserString=$vUserString + $user.SamAccountName + "`r"
Enable-Mailbox -Identity $user.name -Alias $user.SamAccountName
}
[System.Windows.Forms.MessageBox]::Show(
"Les mailboxs ont été activées pour l'OU $vOuID",
"Activation de mailbox",
[System.Windows.Forms.MessageBoxButtons]::Ok,
[System.Windows.Forms.MessageBoxIcon]::Warning,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
)
}
}
} until ($vOuID -eq "")
Suppression de boîtes aux lettres
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
do {
$vUserID = [Microsoft.VisualBasic.Interaction]::InputBox("Introduisez le compte utilisateur auquel la mailbox sera supprimée`n`nCliquer cancel pour arrêter", "DeleteMultipleUsersMailboxes", "")
if ($vUserID -ne "") {
$vUser = Get-User -Identity $vUserID
if ($vUser.RecipientTypeDetails -ne "UserMailbox") {
[System.Windows.Forms.MessageBox]::Show(
"$vUserId n'a pas de boîte aux lettres",
"Erreur",
[System.Windows.Forms.MessageBoxButtons]::Ok,
[System.Windows.Forms.MessageBoxIcon]::Warning,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
)
}
else
{
Disable-Mailbox -Identity $vUser.SamAccountName -Confirm:$false
$vUser = $vUser.name
[System.Windows.Forms.MessageBox]::Show(
"La boîte a été supprimé",
"Suppression de boîte",
[System.Windows.Forms.MessageBoxButtons]::Ok,
[System.Windows.Forms.MessageBoxIcon]::Warning,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
)
}
}
} until ($vUserID -eq "")
0 comments:
Enregistrer un commentaire