+ Post New Thread
Results 1 to 15 of 15
Scripts Thread, Import/modify Active Dirctory user properties from a list in Coding and Web Development; Greetings, This is my first time visiting this site and I've never heard of it before (I wish I have ...
  1. #1

    Join Date
    Aug 2012
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Import/modify Active Dirctory user properties from a list

    Greetings,

    This is my first time visiting this site and I've never heard of it before (I wish I have though). This site seems very well rounded in different IT related fields.

    I have been given a task (I'm not sure why since we have an AD engineer). We are changing phone numbers through the company and need to do the following

    • Add a phone number to a user who ever had a number or cell number
    • Modify an existing cell number or office number


    I know that in AD the general tab and telephones tab both have phone numbers. For us under the general tab telephone number and the IP phone number in the telephone tab are the same.

    I know this can be done via using PowerShell, Scripting or using the LDIFDE command.

    I know batch files and scripting to a limit. I can piece things together but have been able to google something that will help me.

    You assistance is greatly appreciated.

    Thank you

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,696
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by LunchBox View Post
    I know that in AD the general tab and telephones tab both have phone numbers. For us under the general tab telephone number and the IP phone number in the telephone tab are the same.
    Do you have a list of the numbers in a file etc? If so how's it laid out. Can make a script that will just parse through the file and change the numbers, but I'm assuming each person has unique number? If it's text based file (xls etc etc), need to know the layout of the file really

    Thanks,
    Steve

  3. #3

    Join Date
    Jun 2010
    Location
    England
    Posts
    735
    Thank Post
    89
    Thanked 52 Times in 46 Posts
    Rep Power
    35
    Bulk AD Users

    Good tool for bulk editing AD users.

  4. #4
    ADMaster's Avatar
    Join Date
    May 2012
    Posts
    329
    Thank Post
    5
    Thanked 34 Times in 29 Posts
    Rep Power
    23
    In your case I would use bulk AD users as @ihaveaproblem said. It has an import from spreadsheet option. If there are similar tasks that need done on regular basis I would look at writing a powershell script.
    Quest Active directory cmdlets make it very easy to connect to AD and modify users.
    I use this is my all my AD scripts.

  5. #5

    Join Date
    Aug 2012
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Wow, quick response (even though I got this Today).

    My plan is to use a list in a CSV format. My only concern is to match all names for each user, user name, last name and display name. This way we ensure that if there is a change of name by ensuring all name matches there is less chance of error and if one of those do not match then no change is made. Ideally I would like some sort of logic. I can come up with logic with other type of batch files or scripts but not this.

    I prefer to not start with a tool unless it’s naive to AD. The tool will come later if a script does not work the way it was intended. Although that is a nice tool though.

  6. #6
    ascott2's Avatar
    Join Date
    Nov 2007
    Posts
    181
    Thank Post
    18
    Thanked 37 Times in 29 Posts
    Rep Power
    20
    This is a rough and ready powershell script not tested, so try it on a test user. This assumes you have a csv file like

    Surname,Firstname,username,OfficePhone
    Bloggs,Joe,jbloggs,555-1234-5678

    Code:
    Import-CSV C:\usersphone.csv | foreach{
    Get-ADUser -Filter {(sn -eq $_.Surname) -and (givenName -eq $_.FirstName) -and (samaccountname -eq $_.username)} | Set-ADUSer -OfficePhone $_.OfficePhone

  7. #7

    Join Date
    Aug 2012
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks for the reply. I continued googling (while waiting) and found the Import-CSV as one of the options but now my question is this. I exported the CSV and the header is as shown below. The items in green is wha I would like to change.
    Do I need to leave the entire header of the CSV file or can I remove the items that do not need to be changed? I believe I can tell what I can't delete, should be all in red, the ones in black are ones that I have to need to update and or once that I should of selected in red because they need to stay.

    objectClass, objectSid, name, telephoneNumber, givenName, whenCreated, objectGUID, primaryGroupID, sAMAccountName, whenChanged, displayName, userPrincipalName, sn, mobile, description, edsvaNamingContextDN, l, company, department, facsimileTelephoneNumber, mail, homePhone, initials, manager, physicalDeliveryOfficeName, pager, postalCode, postOfficeBox, st, streetAddress, title, wWWHomePage

    I'm assumng that the text in purple are the items that the script will look for in side the CSV file and only update those items?
    Get-ADUser -Filter {(sn -eq $_.Surname) -and (givenName -eq $_.FirstName) -and (samaccountname -eq $_.username)} | Set-ADUSer -OfficePhone $_.OfficePhone

  8. #8


    Join Date
    May 2009
    Posts
    3,018
    Thank Post
    268
    Thanked 799 Times in 605 Posts
    Rep Power
    290
    Quote Originally Posted by LunchBox View Post
    I'm assumng that the text in purple are the items that the script will look for in side the CSV file and only update those items?
    Get-ADUser -Filter {(sn -eq $_.Surname) -and (givenName -eq $_.FirstName) -and (samaccountname -eq $_.username)} | Set-ADUSer -OfficePhone $_.OfficePhone
    Correct(ish). It will; only update OfficePhone. The other fields used by the Get-ADUser filter are just being used to search.

  9. #9
    ascott2's Avatar
    Join Date
    Nov 2007
    Posts
    181
    Thank Post
    18
    Thanked 37 Times in 29 Posts
    Rep Power
    20
    Quote Originally Posted by LunchBox View Post
    Thanks for the reply. I continued googling (while waiting) and found the Import-CSV as one of the options but now my question is this. I exported the CSV and the header is as shown below. The items in green is wha I would like to change.
    Do I need to leave the entire header of the CSV file or can I remove the items that do not need to be changed? I believe I can tell what I can't delete, should be all in red, the ones in black are ones that I have to need to update and or once that I should of selected in red because they need to stay.

    objectClass, objectSid, name, telephoneNumber, givenName, whenCreated, objectGUID, primaryGroupID, sAMAccountName, whenChanged, displayName, userPrincipalName, sn, mobile, description, edsvaNamingContextDN, l, company, department, facsimileTelephoneNumber, mail, homePhone, initials, manager, physicalDeliveryOfficeName, pager, postalCode, postOfficeBox, st, streetAddress, title, wWWHomePage

    I'm assumng that the text in purple are the items that the script will look for in side the CSV file and only update those items?
    Get-ADUser -Filter {(sn -eq $_.Surname) -and (givenName -eq $_.FirstName) -and (samaccountname -eq $_.username)} | Set-ADUSer -OfficePhone $_.OfficePhone
    If the CSV is for purely just updating telephone numbers then all you need in the csv is the affected telephone attributes ir OfiicePhone, mobile etc. and some way of identifying the user it is associated with. You could have just the samaccountname and the numbers as a minimum, but as you said you wanted a sure check of users incase of name changes the minimum you would need is FirstName(AD=givenname),Surname(AD=sn), and the username(AD=samaccountname) plus any phone number attributes you intend on recording. However, it will do no harm leaving in the additional headers as we just pick out the columns we need. In keeping it like this it gives scope to use this csv for more than just numbers in the future.

    Personally, unless it's an attribute that isn't currently populated I don't use spreadsheets or csv's to manage the AD as it adds and extra overhead, instead update the AD directly, as that is the authoritive store(Unless you are getting your data from another source ofcourse ie your MIS). If you need to get the information in a spreadsheet for distribution for example you can always export the data from the AD.

  10. #10

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,611
    Thank Post
    647
    Thanked 1,616 Times in 1,446 Posts
    Rep Power
    421
    We use Dovestones AD Bulk Users for our AD management and it could do this fo you.

    Ben

  11. #11
    maark's Avatar
    Join Date
    Feb 2006
    Location
    leicester
    Posts
    472
    Thank Post
    90
    Thanked 74 Times in 66 Posts
    Rep Power
    38
    Quote Originally Posted by plexer View Post
    We use Dovestones AD Bulk Users for our AD management and it could do this fo you.

    Ben
    Just bought the latest version of this and it is great - for £132 online price it is a bargain - you can do bulk modify/ creation and it has other tools as well.

  12. #12

    Join Date
    Aug 2012
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    ascott2 do you import the exported file from AD back into AD? Or how would you make those changes?

  13. #13

    Join Date
    Aug 2012
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Also,

    I think I want to capture error and googled but I don't know what to look for but this is what I came up this with the cool scrip that ascott2 gave me.

    Ideally I would like to capture any error but continue with the script to a file like c:\ERROR.TXT (OR CSV)

    Code:
    Import-CSV C:\usersphone.csv | foreach{
    Try{
    Get-ADUser -Filter {(sn -eq $_.Surname) -and (givenName -eq $_.FirstName) -and (samaccountname -eq $_.username)} | Set-ADUSer -OfficePhone $_.OfficePhone
    }Catch SOMETHING HERE
    }
    }

  14. #14


    Join Date
    May 2009
    Posts
    3,018
    Thank Post
    268
    Thanked 799 Times in 605 Posts
    Rep Power
    290
    There's a nice powershell script here which takes info from a csv and creates new users. It deals with extended attributes and writes details of the run to a log file. It's reasonably well documented, so is easy to see what is going on and modify. 2008 R2 only though (because it relies on Active Directory module).

  15. #15

    Join Date
    Aug 2012
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    pcstru - thanks for the link, cool script. unfortunately its a little beyond my skill to get the info I need to my mine export errors

SHARE:
+ Post New Thread

Similar Threads

  1. Import fictional active directory users
    By FN-GM in forum General Chat
    Replies: 13
    Last Post: 24th February 2012, 06:51 PM
  2. Replies: 1
    Last Post: 7th November 2008, 07:27 PM
  3. Replies: 6
    Last Post: 29th February 2008, 12:03 AM
  4. Replies: 30
    Last Post: 24th November 2006, 08:33 AM
  5. Replies: 3
    Last Post: 16th November 2006, 09:55 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •