0

Where am I going wrong in the script here? It doesn't give me any error. But it doesn't remove

$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
        }
    }
}
Davidw
  • 1,210
  • 3
  • 14
  • 24
Aharna
  • 1

0 Answers0