我需要帮助从 AD LDS 域中删除批量用户的邮件属性

我需要帮助从 AD LDS 域中删除批量用户的邮件属性

这里的脚本哪里出错了?它没有给出任何错误。但它没有删除

$cred= get-credential "s2\svcfimadamadmapeu"

$CSV= Get-content '.\input.csv'

function UpdateADAMUserDetails
{
    param(
        [string] $ADCN,
        [string] $mail
                
      )
        
    $domaininfo = new-object DirectoryServices.DirectoryEntry("LDAP://b-004.ldap.unilever.com/DC=D1,DC=MS,DC=Unilever,DC=COM",$ADAMCredential.GetNetworkCredential().UserName,$ADAMCredential.GetNetworkCredential().Password)
    
    $ADAMsearcher = new-object DirectoryServices.DirectorySearcher($domaininfo)
    $ADAMsearcher.filter = “(&(ObjectClass=userProxyFull)(CN=$ADCN))”
    $ADAMsearcher.CacheResults = $true
    $ADAMsearcher.SearchScope = 'Subtree'
    $ADAMsearcher.PageSize = 1000
    $ADAMUserAttributes=$ADAMsearcher.FindOne()
    
    
    if ($ADAMUserAttributes)
    {
       $entryToUpdate =  $ADAMUserAttributes.GetDirectoryEntry()
                              
       
        if($mail)
        {
            $entryToUpdate.Put("mail",$Null)
         
        }
        
        try
        {
            $entryToUpdate.SetInfo()
            WriteLog "Success: removed mail in ADAM `r"
        }
        catch
        {
             WriteLog "Error: $UserID Couldn't remove mail in ADAM `r"
        "Error: $UserID Couldn't remove mail in ADAM `r" | out-file ".\out.csv" -append
        }
    }
}

相关内容