“Couldn’t find object” while modifying Message Delivery Restrictions

Hi Readers,

Sharing one of the issue which every Exchange L1/L2 Admin face, while modifying Message Delivery Restrictions.

Capture1

 

If there are terminated users in the restriction list i.e. users that don’t have mailbox you get below error:

Capture2

Now to fix this just download & extract the zip file from below link, run the batch file

https://gallery.technet.microsoft.com/scriptcenter/Distribution-List-Message-a71c9798

This will ask you to enter the group name, for which you want to fix the Modify Message Delivery Restriction issue.

Logs will be created in the logs folder where you can check the restriction list that was in use & that has been applied after removing the problematic users.

################################################################################################# 
#            Author: Lokesh Agarwal 
#            Reviewer: Vikas Sukhija 
#            Modfied: 05/02/1015 
#            Description: Fix Restriction list in distribution groups 
# 
# 
################################################################################################# 
 
Param( 
  [string]$name 
) 
 
####################################Define Logs############################## 
 
$date = get-date -format d 
$date = $date.ToString().Replace(“/”, “-”) 
 
$time = get-date -format t 
$time = $time.ToString().Replace(":""-"$time = $time.ToString().Replace(" """) 
 
$log1 = ".\Logs" + "\" + "ExistingR_" + $date + "_" + $time + "_.log" 
$log2 = ".\Logs" + "\" + "NewR_" + $date + "_" + $time + "_.log" 
 
##############################ADD Shell##################################### 
 
If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null) 
{ 
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
} 
 
$nameread-host "Please enter group name that needs to be fixed" 
 
$DLCurrent = Get-DistributionGroup -identity $name 
$DLTerminateUser = @((Get-DistributionGroup -identity $name ).AcceptMessagesOnlyFrom | %{$_.distinguishedname}) 
$TermCount = $DLTerminateUser.Count 
Write-host "Total restriction count $TermCount for $name" 
Add-content $log1 "Total restriction count $TermCount for $name" 
Add-content $log1 $DLTerminateUser 
 
        while ($TermCount -ne 0) 
        { 
            if (!(Get-Mailbox $DLTerminateUser[$TermCount - 1])) 
            { if(!(Get-DistributionGroup -identity $DLTerminateUser[$TermCount - 1])) 
                    { 
            $DLCurrent.AcceptMessagesOnlyFrom 
            $DLCurrent.AcceptMessagesOnlyFrom -$DLTerminateUser[$TermCount - 1] 
            $DLCurrent.AcceptMessagesOnlyFrom 
                      } 
            }           
 
        $TermCount = $TermCount - 1 
        } 
 
                 if($error -like "*couldn't be found*") 
                   { 
            $error.clear() 
           } 
        $countitems$DLCurrent.AcceptMessagesOnlyFrom 
        $countit = $countitems.count 
        Write-host "Total restriction count after removing Term users from $name is $countit" 
        Add-content $log2 "Total restriction count after removing Term users from $name is $countit" 
        Add-content $log2 $countitems 
 
        timeout 20 
Set-DistributionGroup -identity $name -AcceptMessagesOnlyFrom $DLCurrent.AcceptMessagesOnlyFrom         
        timeout 20 
 
        $DLCurrent2 = Get-DistributionGroup -identity $name 
        $DLTerminateUser2 = @((Get-DistributionGroup -identity $name ).AcceptMessagesOnlyFrom | %{$_.distinguishedname}) 
 
        $TermCount2 = $DLTerminateUser2.Count 
                Write-host "Final restriction count after removing Term users from $name is $TermCount2" 
        Add-content $log2 "Final restriction count after removing Term users from $name is $TermCount2" 
 
 
##############################################################################################################
Regards
Sukhija Vikas
Advertisements

8 thoughts on ““Couldn’t find object” while modifying Message Delivery Restrictions

  1. There are chances that the users to whom we have provided access to send mails to particular group, those users AD ID and Mailbox is in disabled state and Still those IDs will be part of ” Only senders in the following list”. In this case we cannot modify this list until we remove those disabled users from one of the attribute of the DL. My question is, does this powershell script works in this scenario as well?

  2. just create DL.txt & belwo is the modified code:

    $dllist = gc .\dl.txt

    $dllist | foreach-object{

    $name= $_

    $DLCurrent = Get-DistributionGroup -identity $name
    $DLTerminateUser = @((Get-DistributionGroup -identity $name ).AcceptMessagesOnlyFrom | %{$_.distinguishedname})
    $TermCount = $DLTerminateUser.Count
    Write-host “Total restriction count $TermCount for $name”
    Add-content $log1 “Total restriction count $TermCount for $name”
    Add-content $log1 $DLTerminateUser

    while ($TermCount -ne 0)
    {
    if (!(Get-Mailbox $DLTerminateUser[$TermCount – 1]))
    { if(!(Get-DistributionGroup -identity $DLTerminateUser[$TermCount – 1]))
    {
    $DLCurrent.AcceptMessagesOnlyFrom
    $DLCurrent.AcceptMessagesOnlyFrom -= $DLTerminateUser[$TermCount – 1]
    $DLCurrent.AcceptMessagesOnlyFrom
    }
    }

    $TermCount = $TermCount – 1
    }

    if($error -like “*couldn’t be found*”)
    {
    $error.clear()
    }
    $countitems= $DLCurrent.AcceptMessagesOnlyFrom
    $countit = $countitems.count
    Write-host “Total restriction count after removing Term users from $name is $countit”
    Add-content $log2 “Total restriction count after removing Term users from $name is $countit”
    Add-content $log2 $countitems

    timeout 20
    Set-DistributionGroup -identity $name -AcceptMessagesOnlyFrom $DLCurrent.AcceptMessagesOnlyFrom
    timeout 20

    $DLCurrent2 = Get-DistributionGroup -identity $name
    $DLTerminateUser2 = @((Get-DistributionGroup -identity $name ).AcceptMessagesOnlyFrom | %{$_.distinguishedname})

    $TermCount2 = $DLTerminateUser2.Count
    Write-host “Final restriction count after removing Term users from $name is $TermCount2”
    Add-content $log2 “Final restriction count after removing Term users from $name is $TermCount2”
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s