Reputation: 4445
I am writing a Powershell script for managing Exchange Distribution Groups and Public Folders.
In the Public Folder Management Console, I have created a Mail Enabled folder. In that folder's Properties, under the E-Mail Addresses tab, I want to remove all the occurrences of email addresses that contain "Correspondence" from the list.
My question is, how would you go about removing email addresses from a public folder's properties by using Powershell?
If you want to see a piece of code, here it is:
# create the new public folder
New-PublicFolder -Name $nextProjectName -Path "\Projets"
Add-PublicFolderClientPermission -Identity "\Projets\$nextProjectName" -AccessRights CreateItems, ReadItems, CreateSubfolders, EditOwnedItems, FolderVisible, DeleteOwnedItems -User $nextProjectName
New-PublicFolder -Name "Correspondance" -Path "\Projets\$nextProjectName"
Enable-MailPublicFolder -Identity "\Projets\$nextProjectName\Correspondance"
$correspondanceAlias = $nextProjectCode.Substring(1,6)
Set-MailPublicFolder -Identity "\Projets\$nextProjectName\Correspondance" -Alias "bccp$correspondanceAlias" -DisplayName "bccp$correspondanceAlias"
Here is the screenshot showing in detail what I want to remove. The two SMTP addresses and the second one of the two X400 addresses.
Upvotes: 1
Views: 7279
Reputation: 4445
I have resolved the issue. All I did is to repeat the cmdlet that sets the properties of the public folder to add the email addresses, so the wrong email addresses never appear.
$correspondanceAlias = $nextProjectCode.Substring(1,6)
Set-MailPublicFolder -Identity "\Projets\$nextProjectName\Correspondance" -Alias "bccp$correspondanceAlias" -DisplayName "bccp$correspondanceAlias"
Set-MailPublicFolder -Identity "\Projets\$nextProjectName\Correspondance" -EmailAddresses "[email protected]", "[email protected]"
Upvotes: 1
Reputation: 68243
Not tested, but I think this should work:
foreach ($mailpf in get-mailpublicfolder){
$addrs = $mailpf.emailaddresses |
where {$_.proxyaddressstring -notmatch "smtp:.*correspondence.*"}
set-mailpublicfolder $mailpf.identity -emailaddresses $addrs -whatif
}
Upvotes: 1