The fastest way to remove @target.local from AD objects across the Org:
Get-Mailbox -organizationalunit 'dc=domain,dc=local' | % { $a = $_.emailaddresses; $b = $_.emailaddresses; foreach($e in $a) { if ($e.tostring() -match "target.local") { $b -= $e; } } ; $_ Set-Mailbox -emailaddresses $b }
Get-DistributionGroup -organizationalunit 'dc=domain,dc=local' | % { $a = $_.emailaddresses; $b = $_.emailaddresses; foreach($e in $a) { if ($e.tostring() -match "target.local") { $b -= $e; } } ; $_ Set-DistributionGroup -emailaddresses $b }
Get-DynamicDistributionGroup -organizationalunit 'dc=domain,dc=local' | % { $a = $_.emailaddresses; $b = $_.emailaddresses; foreach($e in $a) { if ($e.tostring() -match "target.local") { $b -= $e; } } ; $_ Set-DynamicDistributionGroup -emailaddresses $b }
Get-MailContact -organizationalunit 'dc=domain,dc=local' | % { $a = $_.emailaddresses; $b = $_.emailaddresses; foreach($e in $a) { if ($e.tostring() -match "target.local") { $b -= $e; } } ; $_ Set-MailContact -emailaddresses $b }
Get-MailPublicFolder -organizationalunit 'dc=domain,dc=local' | % { $a = $_.emailaddresses; $b = $_.emailaddresses; foreach($e in $a) { if ($e.tostring() -match "target.local") { $b -= $e; } } ; $_ Set-MailPublicFolder -emailaddresses $b }
Get-MailUser -organizationalunit 'dc=domain,dc=local' | % { $a = $_.emailaddresses; $b = $_.emailaddresses; foreach($e in $a) { if ($e.tostring() -match "target.local") { $b -= $e; } } ; $_ Set-MailUser -emailaddresses $b }
#Get-Recipient -organizationalunit 'dc=domain,dc=local' | % { $a = $_.emailaddresses; $b = $_.emailaddresses; foreach($e in $a) { if ($e.tostring() -match "target.local") { $b -= $e; } } ; $_ Set-Recipient -emailaddresses $b }
No comments:
Post a Comment