write a script in powershell to find proxies with the local domain .loc in all shared…
- User
write a script in powershell to find proxies with the local domain .loc in all shared mailboxes in exchange organization and remove them
- Assistant
write a script in powershell to find proxies with the local domain .loc in all shared mailboxes in exchange organization and remove them
Creating a script to find and remove proxy addresses with a specific domain (e.g., .loc) for all shared mailboxes in an Exchange organization involves utilizing PowerShell and its Exchange Management Shell capabilities. Before proceeding, ensure you have the necessary permissions to execute these commands, usually requiring Exchange Administrator rights.
The script below performs the following actions:
.loc domain.# Ensure you are connected to Exchange Management Shell or have imported the Exchange module
# Retrieve all shared mailboxes in the organization
$sharedMailboxes = Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited
foreach ($mailbox in $sharedMailboxes) {
$proxyAddresses = $mailbox.EmailAddresses
$removeProxies = $proxyAddresses | Where-Object { $_ -like "*@*.loc" }
if ($removeProxies.Count -gt 0) {
Write-Host "Removing proxy addresses for $($mailbox.Name):"
foreach ($proxy in $removeProxies) {
Write-Host " - Removing $($proxy)"
# Constructing the command to remove the proxy address
$newProxies = $proxyAddresses | Where-Object { $_ -ne $proxy }
Set-Mailbox -Identity $mailbox.Identity -EmailAddresses $newProxies
}
} else {
Write-Host "No .loc proxy addresses found for $($mailbox.Name)"
}
}
Write-Host "Proxy address removal process completed."
Set-ExecutionPolicy with caution and consult your organization's security policies.Connect-ExchangeOnline.Remember, PowerShell scripts can be powerful and potentially disruptive tools. Always review and test scripts in a safe environment before applying them to production systems.
Not yet included in a published release.