Solved

Updating AD user fields from CSV file.

Posted on 2011-02-11
6
841 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
Comment Utility

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
Comment Utility
Thank you Chris, I will test and get back to you.
0
 

Author Comment

by:nlewallen
Comment Utility
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
Want to promote your upcoming event?

Is your company attending an event or exhibiting at a trade show soon? Are you speaking at a conference? Spread the word by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility

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
Comment Utility
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
Comment Utility

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

How does your email signature look on mobiles?

Do your employees use mobile devices to reply to emails? With mobile becoming increasingly important to the business world, it is in your best interest to make sure that your email signature looks great across all types of devices.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
In this video we show how to create a User 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 >> Mailb…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now