question

DavidKernaghan-5085 avatar image
0 Votes"
DavidKernaghan-5085 asked IanXue-MSFT answered

Active Directory Contacts

I am trying to import a few hundred users into an OU in our Active Directory as contacts. Not users, please do not tell me to import them as users, i want them as contacts.
I have searched the internet and I have tried numerous scripts and they always fail.
It seems to come down to the fact that I have unrecognised parameters.
This is the code and the error I am getting:

Import-Module ActiveDirectory
$Users = Import-CSV C:\Scripts\testimport.csv
foreach($User in $Users){

$Params = @{
'Name' = $User.DisplayName
'mail' = $User.mail

 Path = "OU=X,DC=Y,DC=com"
       }
 New-ADObject  -Type Contact @Params
 }


New-ADObject : A parameter cannot be found that matches parameter name 'mail'.
At line:9 char:29
+ New-ADObject -Type Contact @Params
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-ADObject], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.NewADObject

It works fine without the email bit, but then it's a bit useless and there is no contact information there. I've tried looking at the attribute editor to get the right name of the parameter and it is correct.
The only thing that seems to make sense is that if I do it through the AD and create a user it only asks basic name stuff, nothing about email addresses or phone numbers.
Is it possible I have to create the contacts first and then get another script to populate the fields?

Any help would be appreciated.

Thank you
DK

windows-server-powershellwindows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

Hi,

As the error message said the New-ADObject cmdlet doesn't have the "-mail" parameter. To set the "mail" attribute you can use the "-OtherAttributes" parameter.

 $Params = @{
     'Name' = $User.DisplayName
     'OtherAttributes' = @{'mail'=$User.mail}
     'Path' = "OU=X,DC=Y,DC=com"
 }
 New-ADObject -Type Contact @Params

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.