Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Active Directory and PowerShell

Thread: Problems with Import-csv | New-QADuser

This question is answered.


Permlink Replies: 7 - Pages: 1 - Last Post: Nov 23, 2009 1:06 PM by: Shay Levy
RTeal

Posts: 27
Registered: 11/20/09
Problems with Import-csv | New-QADuser
Posted: Nov 20, 2009 5:34 PM
 
  Click to reply to this thread Reply

Hello,
I get the following error trying to import users with New-QADUser

Import-Csv c:\admin\users4.csv | New-QADUser -ParentContainer my.org/testou -Import

New-QADUser : Pipeline input cannot be processed because the default value of parameter 'Name' cannot be retrieved. Can not set property value because "Name" is a write-only property.
At line:1 char:45

I created a CSV just like on Dmitry's site but still no luck

http://dmitrysotnikov.wordpress.com/2008/01/21/ad-user-provisioning-from-csv-got-easier/


Thanks




Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Problems with Import-csv | New-QADuser
Posted: Nov 21, 2009 4:48 AM   in response to: RTeal
 
  Click to reply to this thread Reply

See this thread:

http://powergui.org/thread.jspa?messageID=31984

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
RTeal

Posts: 27
Registered: 11/20/09
Re: Problems with Import-csv | New-QADuser
Posted: Nov 22, 2009 10:40 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

Thanks, that helps but I hit a wall a little further. I've found if my spreadsheet does not contain an entry for -Title I receive the following error:

The attribute syntax specified to the directory service is invalid. (Exception from HRESULT: 0x8007200B)

How can I work around this problem because not all users will have all attributes?

import-csv C:\admin\users5.csv | foreach-object {new-qadUser -ParentContainer 'OU=testou,DC=mydomain,DC=org' -name $_.'name' -SamAccountName $_.'samaccountname' -FirstName $_.'firstname' -LastName $_.'lastname'-StreetAddress $_.'streetaddress' -Title $_.'title'}

Many thanks




Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Problems with Import-csv | New-QADuser
Posted: Nov 22, 2009 10:49 AM   in response to: RTeal
 
  Click to reply to this thread Reply

So why don't you remove the '-title $_.title' from the command? I wonder why you get the error, -title can get/set null values...

Anyway, you dont have to wrap properties in quotes (i.e $_.'samaccountname' ). You can simply write $_.samaccountname. Wrapping in quotes is neccessar only if the property has a space in the name ($_.'samacco untname' ).

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
RTeal

Posts: 27
Registered: 11/20/09
Re: Problems with Import-csv | New-QADuser
Posted: Nov 22, 2009 11:55 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

Hi Shay,

I plan to use get-qaduser to export the properties of a group of users from one domain and then import the users in another. Some will have title (or address, pager, etc.) listed and some won't.

The problem is definitely with null values because if I add a placeholder like TBD to the title field on the spreadsheet the import works, but I don't want a bunch of placeholder information in the directory.

Thanks for any ideas for resolving this issue.




Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Problems with Import-csv | New-QADuser
Posted: Nov 22, 2009 12:06 PM   in response to: RTeal
 
  Click to reply to this thread Reply

I don't have access to my AD lab at the moment, what if you run this for a single test user:

Get-QADUser testUser | Set-QADUser -Title $null

By the way, did you download the new version of the cmdlets (1.3)? If not, it is worth trying with the new version.


Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
RTeal

Posts: 27
Registered: 11/20/09
Re: Problems with Import-csv | New-QADuser
Posted: Nov 23, 2009 10:48 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

Hi Shay,

Get-QADUser testUser | Set-QADUser -Title $null will remove the test user's title. The command also runs without error if the Title field is already blank.

I'm using the 1.3 version of the commands.

Robert


Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Problems with Import-csv | New-QADuser
Posted: Nov 23, 2009 1:06 PM   in response to: RTeal
Answered
  Click to reply to this thread Reply

Then I don't see a reason why $_.title, even if not exist would cause the command to fail (it should be $null).

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums