Solved

Updating AD user fields from CSV file.

Posted on 2011-02-11
6
846 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
[X]
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
6 Comments
 
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.

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
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
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

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 71

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

Is Your AD Toolbox Looking More Like a Toybox?

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.

Question has a verified solution.

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

A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In this video we show how to create a Contact 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 >> Contact ta…
In this video we show how to create a mailbox database 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 Servers >> Data…

737 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