LunchBox Posted August 11, 2012 Posted August 11, 2012 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
Steve21 Posted August 11, 2012 Posted August 11, 2012 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
ihaveaproblem Posted August 11, 2012 Posted August 11, 2012 Bulk AD Users Good tool for bulk editing AD users.
ADMaster Posted August 11, 2012 Posted August 11, 2012 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.
LunchBox Posted August 13, 2012 Author Posted August 13, 2012 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.
ascott2 Posted August 14, 2012 Posted August 14, 2012 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 Import-CSV C:\usersphone.csv | foreach{ Get-ADUser -Filter {(sn -eq $_.Surname) -and (givenName -eq $_.FirstName) -and (samaccountname -eq $_.username)} | Set-ADUSer -OfficePhone $_.OfficePhone
LunchBox Posted August 15, 2012 Author Posted August 15, 2012 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
pcstru Posted August 15, 2012 Posted August 15, 2012 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.
ascott2 Posted August 15, 2012 Posted August 15, 2012 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.
plexer Posted August 15, 2012 Posted August 15, 2012 We use Dovestones AD Bulk Users for our AD management and it could do this fo you. Ben
maark Posted August 15, 2012 Posted August 15, 2012 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.
LunchBox Posted August 16, 2012 Author Posted August 16, 2012 ascott2 do you import the exported file from AD back into AD? Or how would you make those changes?
LunchBox Posted August 17, 2012 Author Posted August 17, 2012 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) Import-CSV C:\usersphone.csv | foreach{ [color=#ff0000]Try{[/color] Get-ADUser -Filter {(sn -eq $_.Surname) -and (givenName -eq $_.FirstName) -and (samaccountname -eq $_.username)} | Set-ADUSer -OfficePhone $_.OfficePhone [color=#ff0000]}Catch SOMETHING HERE } }[/color]
pcstru Posted August 17, 2012 Posted August 17, 2012 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).
LunchBox Posted August 17, 2012 Author Posted August 17, 2012 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now