How to Create Contacts using Powershell?

Hello,

In my normal AD machine, I can create Contact using ADUC in any OU.

By using Quest AD module, I can create Contact using following cmdlet or script -

Import-Csv $Path | foreach{New-QADObject -ParentContainer "OU=Contacts,DC=first,DC=domain,DC=com" -type "Contact" -name $_.DisplayName -ObjectAttributes @{displayName=$_.DisplayName;mailNickname=$_.Alias;mail=$_.ExternalEmailAddress;proxyAddresses=$_.ExternalEmailAddress}}

But I need to create CONTACT using Inbuilt Windows PowerShell "Import-Module ActiveDirectory" - and that too without using any Quest AD module.

Please help me with cmdlet or script through which I can create contact directly (manually entering details in PowerShell) or from CSV.

Thanks,

Divyaprakash Koli


  • Edited by Divyaprakash Monday, September 23, 2013 2:51 PM Grammar
September 23rd, 2013 2:50pm

New-ADObject

http://technet.microsoft.com/en-us/library/ee617260.aspx

See Example #3

Free Windows Admin Tool Kit Click here and download it now
September 23rd, 2013 3:04pm

Hi,

Contact is created by New-Object cmldlet in PowerShell like this :

new-adobject -Type contact -Name "contactName" -DisplayName "DisplayName "  -Description " Des "  

For more info :

http://technet.microsoft.com/en-us/library/ee617260.as

September 23rd, 2013 3:09pm

Hello Tarique,

Thanks for your cmdlet.

I tried it and contact is being created under main domain.com, but I want to give path or ParentContainer as I used to give under Quest Module, for e.g. If I want to create Contact in OU=Demo.

Please guide.

Thanks,

Divyaprakash Koli

Free Windows Admin Tool Kit Click here and download it now
September 23rd, 2013 4:37pm

Hello Tarique,

Additionally, I don't wish to include "DC=domain,DC=com" as I am directly running script on same server.

If not then I can put "domain.com" directly.

Is there any provision for this requirement?

Thanks,

Divyaprakash Koli

September 23rd, 2013 4:49pm

Hello Tarique,

Thanks for your cmdlet.

I tried it and contact is being created under main domain.com, but I want to give path or ParentContainer as I used to give under Quest Module, for e.g. If I want to create Contact in OU=Demo.

Please guide.

Thanks,

Divyaprakash Koli

Hi ,

You can include  -path parameter  , which specify where you want to create / store your AD contact .

for example  :

New-ADObject -Type contact -name Tarique -Path "ou=OuName,dc=domain,dc=com"

Free Windows Admin Tool Kit Click here and download it now
September 23rd, 2013 4:55pm

Hello Tarique,

Additionally, I don't wish to include "DC=domain,DC=com" as I am directly running script on same server.

If not then I can put "domain.com" directly.

Is there any provision for this requirement?

Thanks,

Divyaprakash Koli

No , you can't use  "domain.com" directly . You have to use the complete path  as Distinguished Name format .

one thing you can do , store  the path in a Variable like this :

$path="ou=Myou,dc=domain,dc=com" 

then  use like this :

New-ADObject -Type contact -name Tarique -Path $path

September 23rd, 2013 4:59pm

Hello Tarique,

Thanks for you time and efforts.

Finally, the below one is working for me -

Import-Csv $Path | foreach{New-ADObject -Type Contact -Name $_.DisplayName -OtherAttributes @{'displayName'=$_.DisplayName;'mail'=$_.ExternalEmailAddress;'proxyAddresses'=$_.ExternalEmailAddress;'givenName'=$_.FirstName;'sn'=$_.LastName;'physicalDeliveryOfficeName'=$_.OfficeLocation;'telephoneNumber'=$_.TelephoneNumber;'mobile'=$_.MobileNumber;'facsimileTelephoneNumber'=$_.FaxNumber;'streetAddress'=$_.StreetAddress;'postOfficeBox'=$_.'P.O.Box';'l'=$_.City;'st'=$_.StateorProvince;'postalCode'=$_.PostalCode;'c'='AU';'Title'=$_.JobTitle;'department'=$_.Department;'company'=$_.Company} -Path "OU=$ou1,OU=$ou2,DC=$dc1,DC=$dc2,DC=$dc3"}

Thanks,

Divyaprakash Koli

  • Marked as answer by Divyaprakash Monday, September 23, 2013 10:27 PM
Free Windows Admin Tool Kit Click here and download it now
September 23rd, 2013 10:27pm

I am glad to help you.


September 24th, 2013 3:40am

Hello,

Is it possible to create this contact without creating a @domain email address? I only want an external address for my contacts. At this point I have to remove the @domain email address after the contact is created. Thank you

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2014 3:54pm

Yes, if using the ActiveDirectory module to create a contact,  a 'mail' attribute is not mandatory.  The only attribute you must specify a value for is 'name'.

New-ADObject -Type contact -Name "Test Contact"
If using the Exchange module to create contacts, I believe email addresses are required, IIRC.


August 8th, 2014 6:11pm

Here is my little addition to all of these great examples:

Import-Csv $path | ForEach {New-MailContact -Name $_.FirstName -Alias $_.Alias -ExternalEmailAddress $_.ExternalAddress -OrganizationalUnit "OU=xxxxxxxxxxx,OU=xxxxxxxxx,DC=xx,DC=xx,DC=xx" | Set-MailContact -HiddenFromAddressListsEnabled $true}

In the case of my company, we, for security meassures, hide every external contact, so there you have how to, after creating them all.

Cheers!

Free Windows Admin Tool Kit Click here and download it now
June 17th, 2015 4:00pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics