Solved

Updating AD user fields from CSV file.

Posted on 2011-02-11
6
844 Views
Last Modified: 2012-05-11
This post is related to : http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_24870528.html#a34868508 

Just want to verify that I am understanding the syntax changes, say I want to update the description, telephone, and office, the syntax for the lower half would read as follows;

Import-CSV $Csv | ForEach-Object {
  Set-QADUser $_.DN -Description $_.description -Telephone $_.telephoneNumber -Office $_.physicalDeliveryOfficeName
}
0
Comment
Question by:nlewallen
  • 3
  • 3
6 Comments
 
LVL 70

Expert Comment

by:Chris Dent
ID: 34872482

It'll be fine with that, yes.

The documentation for the CmdLet has it use PhoneNumber in place of Telephone:
Import-CSV $Csv | ForEach-Object {
  Set-QADUser $_.DN -Description $_.description -PhoneNumber $_.telephoneNumber -Office $_.physicalDeliveryOfficeName
}

Open in new window

But the parameter has an alias (TelephoneNumber) so it should work anyway.

Chris
0
 

Author Comment

by:nlewallen
ID: 34872695
Thank you Chris, I will test and get back to you.
0
 

Author Comment

by:nlewallen
ID: 34873688
Ran into a hiccup, was returned the following error:

$OuDomain = "dc=local,dc=testserver,dc=com" $Csv =
 "c:\importfile.csv" Import-CSV $Csv | ForEach-Object { Set-QADUser $_.DN -Descr
iption $_.description -PhoneNumber $_.telephoneNumber -Office $_.physicalDeliver
yOfficeName}
Unexpected token 'Csv' in expression or statement.
At line:1 char:48
+ $OuDomain = "dc=local,dc=testserver,dc=com" $Csv <<<<  = "c:\importfile.csv" I
mport-CSV $Csv | ForEach-Object { Set-QADUser $_.DN -Description $_.description
 -PhoneNumber $_.telephoneNumber -Office $_.physicalDeliveryOfficeName}
    + CategoryInfo          : ParserError: (Csv:String) [], ParentContainsErro
   rRecordException
    + FullyQualifiedErrorId : UnexpectedToken

[PS] C:\Users\llamallamaduck\Desktop>$_.physicalDeliveryOfficeName
}
    + CategoryInfo          : OpenError: (:) [Import-Csv], FileNotFoundExcepti
   on
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.Im
   portCsvCommand

Open in new window


When I converted the file to '.csv' I did receive an error message, but didn't think anything of it till now. I attached the error message file via picture. I am using Microsoft Excel 2010


excelError.jpg
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 70

Expert Comment

by:Chris Dent
ID: 34873730

You need some line breaks in there, are you trying to put it all on one line? PS will be quite happy spreading things out.
$OuDomain = "dc=local,dc=testserver,dc=com"
$Csv = "c:\importfile.csv" 
Import-CSV $Csv | ForEach-Object { 
  Set-QADUser $_.DN -Description $_.description -PhoneNumber $_.telephoneNumber -Office $_.physicalDeliveryOfficeName
}

Open in new window

If you just want to test the CSV file, run this:
Import-CSV "c:\importfile.csv"

Open in new window

Chris
0
 

Author Comment

by:nlewallen
ID: 34874134
I have bad luck apparently.

 [PS] C:\Users\llamallamaduck\Desktop>$OuDomain = "dc=local,dc=testserver,dc=com"
[PS] C:\Users\llamallamaduck\Desktop>$Csv = "c:\import.csv"
[PS] C:\Users\llamallamaduck\Desktop>Import-CSV $Csv | ForEach-Object {
>>   Set-QADUser $_.DN -Description $_.description -PhoneNumber $_.telephoneNumb
er -Office $_.physicalDeliveryOfficeName
>> }
>>
The term 'Set-QADUser' is not recognized as the name of a cmdlet, function, scr
ipt file, or operable program. Check the spelling of the name, or if a path was
 included, verify that the path is correct and try again.
At line:2 char:14
+   Set-QADUser <<<<  $_.DN -Description $_.description -PhoneNumber $_.telepho
neNumber -Office $_.physicalDeliveryOfficeName
    + CategoryInfo          : ObjectNotFound: (Set-QADUser:String) [], Command
   NotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException 

Open in new window


:S
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 250 total points
ID: 34874234

Ahh not really :)

You either need to install these:

http://www.quest.com/powershell/activeroles-server.aspx

Or if you already did, you need to run this command first of all:

Add-PsSnapIn Quest.ActiveRoles.ADManagement

That'll load the command and should let you execute the rest.

Chris
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this video we show how to create a Shared Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Sha…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question