2013 mar. 27
Purger un domaine des adresses emails
13:38 - Par Bruce JDC - Exchange - Lien permanent
# bjdc-del-emailaddr
#
# Supprimer toutes les addresses smtp liées à un domaine
#
# Condition : les objets ne doivent pas être soumis à une Email Address Policy qui repositionne le domaine à enlever
#
# Entree :
# Domain : nom de domaine, obligatoire
# Type : type d'objet à sauvegarder, obligatoire, choisir entre Mailbox, Contact ou DistrGroup
# NewDomain : le nouveau domaine à mettre en PrimarySmtpAddress si besoin
#
# Author Bruce JDC
param(
[parameter(Mandatory=$true,Position=0)]
[ValidateNotNullOrEmpty()]
[String] $Domain,
[parameter(Mandatory=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[ValidateSet("Mailbox","Contact","DistrGroup")]
[String] $Type,
[parameter(Mandatory=$true,Position=2)]
[ValidateNotNullOrEmpty()]
[String] $NewDomain
)
# chargement du snapin EMS
if (!(get-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin)) {
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
}
# filtre pipeline
filter filter_domain {
if ($_.SmtpAddress -like $Fdomain) {
Write-Output $_
}
}
switch ($Type) {
"Mailbox" {$cmd = 'Get-Mailbox' ; break }
"Contact" {$cmd = 'Get-MailContact' ; break }
"DistrGroup" {$cmd = 'Get-DistributionGroup' ; break }
# si on passe dans default, c'est qu'il y a un gros problème
default {exit}
}
$FDomain = '*@'+ $Domain
$r = Invoke-Expression ($cmd + ' -ResultSize unlimited -Filter { Emailaddresses -like $Fdomain }')
if ($r) {
foreach ($mb in $r) {
# Si le domaine est utilisé dans la primary, on doit changer celui ci
if ($mb.PrimarySmtpAddress -like $FDomain) {
Write-Host ("Changement d'adresse principale : " + $mb.PrimarySmtpAddress + " devient " + ($mb.PrimarySmtpAddress.Local + '@'+$NewDomain))
switch ($Type) {
"Mailbox" {$mb |Set-Mailbox -PrimarySmtpAddress ($mb.PrimarySmtpAddress.Local + '@'+$NewDomain) -EmailAddressPolicyEnabled $false}
"Contact" {$mb | Set-MailContact -PrimarySmtpAddress ($mb.PrimarySmtpAddress.Local + '@'+$NewDomain)-EmailAddressPolicyEnabled $false}
"DistrGroup" {$mb | Set-DistributionGroup -PrimarySmtpAddress ($mb.PrimarySmtpAddress.Local + '@'+$NewDomain) -EmailAddressPolicyEnabled $false}
# si on passe dans default, c'est qu'il y a un gros problème
default {exit}
}
}
$mb = $mb | Update-List -Property EmailAddresses -Remove ($mb.emailaddresses | filter_domain)
switch ($Type) {
"Mailbox" {$mb | Set-Mailbox}
"Contact" { $mb.ExternalEmailAddress = ($mb.PrimarySmtpAddress.ToString()) ;
$mb.HiddenFromAddressListsEnabled = $true ;
$mb | Set-MailContact}
"DistrGroup" {$mb | Set-DistributionGroup}
# si on passe dans default, c'est qu'il y a un gros problème
default {exit}
}
}
} else {
Write-Host "Aucun résultat"
}
Commentaires
Thanks for any other informative website. The place else may I get that kind of information written in such an ideal approach? I have a undertaking that I am just now operating on, and I've been at the glance out for such information.
Le lundi, avril 8 2013, 10:26 par buy and sell,classifieds,canada,toronto, cars, house, selling, classified ads, free
Great writing. Thanks for posting this. I will check to your site to find out more and recommend my acquaintenances about it.
Le mercredi, avril 10 2013, 06:24 par hcg drops
I don't ordinarily comment but I gotta state thanks for the post on this perfect one : D.
Le jeudi, avril 11 2013, 13:01 par hostgator coupon 25
Hello my own spouse! I must declare that benefits and drawbacks incredible, fantastic written you need to include approximately virtually all significant infos. I'm going to discover extra posts this way .
Le mercredi, avril 17 2013, 14:00 par Free Sofwtare to publish your message for free
Like your site. Thanks for writing that. I'll return here to find out more and tell my neighbors about you.
Le dimanche, avril 21 2013, 09:14 par paleo
Heya i�m for the first time here. I found this board and I find It really helpful & it helped me out much. I hope to give one thing back and help others like you helped me.
Le mercredi, avril 24 2013, 01:57 par xbox live codes free
Rattling nice design and style and good content material , hardly anything else we want : D.
Le mercredi, avril 24 2013, 04:25 par claveir arabe
Hey there, I think your site might be having browser compatibility issues. When I look at your website in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, awesome blog!
Le mercredi, avril 24 2013, 04:26 par Macedonian dictionary english
Just want to say your article is as astounding. The clarity in your put up is just great and that i can think you're knowledgeable on this subject. Fine along with your permission let me to take hold of your RSS feed to keep up to date with imminent post. Thanks a million and please continue the rewarding work.
Le vendredi, avril 26 2013, 03:26 par Dealit.ie is the best place to buy and sell anything online in Ireland. Dealit.ie