Updating AD user fields from CSV file.

Posted on 2011-02-11
Medium Priority
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
Question by:nlewallen
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 71

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.


Author Comment

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

Author Comment

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
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
    + FullyQualifiedErrorId : UnexpectedToken

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

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

LVL 71

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


Author Comment

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
    + FullyQualifiedErrorId : CommandNotFoundException 

Open in new window

LVL 71

Accepted Solution

Chris Dent earned 1000 total points
ID: 34874234

Ahh not really :)

You either need to install these:


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.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
In this video we show how to create an Address List 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 Organization >> Ad…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
Suggested Courses

752 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