Standing next to me is a Person with multiple pieces of paper. Each of them having Telephone numbers of all the different companies they work with. Just looking at the pages you can see this has been coming along for a while. Updating this list has now turned into writing additional information on the pages.
Since we did a Company Directory, why not create a Supplier Directory.
What is the difference
When Creating objects in AD you make it for a specific reason. A User is created to be able to logon to various organization-owned equipment, whether this is Physical or Virtual. Thus it gets an attribute called a SAM account sAMAccountname
A Contact on the other hand does not need to connect to any of the organization’s services but you might want them to appear in the Exchange Address book as some sort of Partner to the Organization. This means no sAMAccountname.
When setting up the directory we need to use different attributes to pull the list successfully and Populate the new Supplier directory. In addition to this, there were a lot of pages with numbers which was not gonna be created Manually. Rather, importing this into AD.
New-ADObject
The New-ADObject cmdlet creates a new Active Directory object such as a new organizational unit or new user account. You can use this cmdlet to create any type of Active Directory object. Many object properties are defined by setting cmdlet parameters. Properties that are not set by cmdlet parameters can be set by using the OtherAttributes parameter.
–Powershell Help
Since Microsoft even gave us an example of how to import a contact a Few simple trail and errors gave the following command that would allow the creation of a contact.
Example
New-ADObject -Name "Fluke" -Type contact -Path "OU=PhoneDirectory,DC=ForFlukeSake,DC=co,DC=za"
-OtherAttributes @{‘GivenName’=”Fluke“;’company’=”FFS“;’telephonenumber’=”(000) 000 0000“;’mail’=”NoReply@forflukesake.co.za“;’mobile’=”(000) 000 0000“}
The Import file
The Only thing remaining is creating a file to import the Contacts from.
Properly formatting the file before import does make the Supplier Portal look Professional. So Naturally use your numerous Excel Skills to properly format the File.
The File with the headings will look like The Following:
This will then be save as a Comma Separated CSV file:
Heading | Data |
Firstname | Fluke |
noreply@forflukesake.co.za | |
Telephone | (111) 111 1111 |
Company | For Fluke Sake |
ou | OU=PhoneDirectory,DC=ForFlukeSake,DC=co,DC=za |
Mobile | (222) 222 2222 |
If the Attributes you need are not in the list you can create one contact in AD. Populate the Attribute you want to import. Then go to the Attribute Editor in Contact Properties. You will have a list of Attributes that are populated which can be used to import.
The Attribute Editor shows when you enable Advance Features in the AD Users and Computers in the View Menu.
PowerShell Script
Once done simply save the file where the script can read it and change the location below so that the script can find it. This was run directly on the Domain Controller.
# Import active directory module for running AD cmdlets Import-Module activedirectory #Store the data from ADUsers.csv in the $ADContacts variable $ADContacts = Import-csv C:\Temp\bulk_users1.csv #Loop through each row containing user details in the CSV file foreach ($Contact in $ADContacts) { #Read user data from each field in each row and assign the data to a variable as below $Firstname = $Contact.firstname $OU = $Contact.ou #This field refers to the OU the user account is to be created in $email = $Contact.email $telephone = $Contact.telephone $company = $Contact.company $Mobile = $Contact.mobile New-ADObject ` -Name $Firstname -Type contact -Path $ou ` -OtherAttributes @{'GivenName'=$Firstname;'company'=$company;'telephonenumber'=$telephone;'mail'=$email;'mobile'=$Mobile} }
See it in Action