Contact
1 TopicAdd Phone Numbers to existing AD Contacts
Dear Community Within the last Days, i had to import ~36000 AD Contacts from Excel. I came from basically zero knowledge and created (copy/paste/edit) following: Contact Import function GetUserAttributes($ht) { $otherAttributes = @{} foreach ($k in $ht.Keys) { if(-not [System.String]::IsNullOrWhiteSpace($ht[$k])) { $otherAttributes.Add($k,$ht[$k]) } } $otherAttributes } ##function CutLeadTrailBlank( $Users = Import-XLSX -Path "\\server\it\Gal_export.xlsx" foreach ($user in $Users) { $Displayname = $user.'Givenname' + ' ' + $user.'surname' $Displayname = $Displayname.Trim() $ht = @{ sn = $user.'Surname' givenName = $user.'GivenName' Displayname = $Displayname mail = $user.'emailaddress' PostalCode = $User.'postalcode' physicalDeliveryOfficeName = $User.'Office' streetAddress = $User.'Streetaddress' l = $User.'City' st = $User.'State' c = $User.'Country' department = $User.'Department' Company = $User.'Company' ##'msDS-SourceObjectDN' = 'OU=Unit3,OU=Unit2D,OU=Unit1,DC=Domain,DC=local' } $otherAttributes = GetUserAttributes($ht) ##$password = $user.Password | ConvertTo-SecureString -AsPlainText -Force if($otherAttributes.Count -gt 0) { New-ADObject -Type contact -name $user.Name -Path 'OU=Unit3,OU=Unit2D,OU=Unit1,DC=Domain,DC=local' -OtherAttributes $otherAttributes } } Enable Mail Contact: Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; $Users = Get-ADObject -LDAPFilter "(objectClass=contact)" -SearchBase 'OU=Unit3,OU=Unit2,OU=Unit1,DC=Domain,DC=local' -Properties Name,Mail ForEach($User in $Users) { $Params1 = @{ Identity = $User.'Name' ExternalEmailAddress = $User.'Mail' } Enable-MailContact @Params1 } Disable EmailAdressPolicy and replace Adresses Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; $Users = Get-MailContact -ResultSize unlimited -organizationalunit 'Domain.local/Unit1/Unit2/Unit3' ForEach($User in $Users) { $Params2 = @{ Identity = $User.'Name' EmailAddressPolicyEnabled = $false EmailAddresses = $User.'ExternalEmailAddress' } Set-Mailcontact @Params2 } I am pretty sure that everything could be done nicer and in one Script, but that worked well. Now i got a new File with just MailAdresses, telephone and Mobilenumbers that i have to add. How to start? My Idea is to read the contacts, read the file, look for corresponding mail addresses and set the phone numbers. How do I find the corresponding contact in AD that matches the mail address from the File? Any Help appreciated! Thanks, Dani7.7KViews0likes1Comment