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

PowerGUI.org PowerGUI.org and blogs

Forums » Request a Script

Thread: Password Import Issues into AD from CSV file

This question is not answered. Helpful answers available: 2. Answered answers available: 1.


Permlink Replies: 4 - Pages: 1 - Last Post: Nov 30, 2009 2:50 PM by: amook_250
amook_250

Posts: 3
Registered: 11/19/09
Password Import Issues into AD from CSV file
Posted: Nov 19, 2009 9:53 AM
 
  Click to reply to this thread Reply

<table border="0" cellspacing="0" cellpadding="4" width="100%"> <tbody> <tr> <td colspan="2">

# Set up variables $data = Import-CSV c:\import.csv
# Database where we are going to put the user mailboxes
$mdb = 'EX07SP1\Mailbox Database'
$ou = 'litwareinc.com/Users'
 #Import the data and create the new mailboxes
ForEach ($i in $data){ $ss = ConvertTo-SecureString $i.password -asPlaintext -Force
$upn = $i.id + "@ehs.com"
New-Mailbox -Password $ss -Database $mdb -UserPrincipalName $upn -name $i.fullname -OrganizationalUnit $ou -SamAccountName $i.id -FirstName $i.firstname -LastName $i.lastname -Displayname $i.fullname }

When I execute the acript I get the following error: Cannot bind argument to parameter 'String' because it is null. At :line:12 char:28 + $ss = ConvertTo-SecureString <<<< $i.password -asPlaintext -Force
 
What I would like to do is when I import the users I would like the password to be the users employee ID #(eight characters) and then they can change it when they log in with Outlook Web Access(users are off site with OWA access on;y).

Below is data from the CSV file:
id,FullName,LastName,FirstName,Password
MAdams,Mike Adams,Adams,Mike,49sbc13!

Any ideas on how to make this work or what the error might be? Thanks, Alex
</td> </tr> </tbody></table>


Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Password Import Issues into AD from CSV file
Posted: Nov 19, 2009 10:44 AM   in response to: amook_250
 
  Click to reply to this thread Reply

What is the output of:

ForEach ($i in $data){ $i.password }



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

Posts: 3
Registered: 11/19/09
Re: Password Import Issues into AD from CSV file
Posted: Nov 29, 2009 9:29 PM   in response to: Shay Levy
 
  Click to reply to this thread Reply

Hi Shay,

I ran the following:

# Set up variables $data = Import-CSV c:\import.csv
# Database where we are going to put the user mailboxes
$mdb = 'EX07SP1\Mailbox Database'
$ou = 'litwareinc.com/Users'
 #Import the data and create the new mailboxes
ForEach ($i in $data){ $i.password }  { $ss = ConvertTo-SecureString $i.password -asPlaintext -Force
$upn = $i.id + "@ehs.com"
New-Mailbox -Password $ss -Database $mdb -UserPrincipalName $upn -name $i.fullname -OrganizationalUnit $ou -SamAccountName $i.id -FirstName $i.firstname -LastName $i.lastname -Displayname $i.fullname }


When I ran this the mailbox wasn't created. I'm using Powergui script editor. I ran the script in external powershell window mode and the output was the contents of the script. I also ran the following script and had the same issue:

# Set up variables

$data = Import-CSV c:\import.csv
$ou = 'litwareinc.com/Users'

#Import the data and create the new mailboxes

ForEach ($i in $data){ $i.password }
{
$ss = ConvertTo-SecureString $i.password -AsPlainText -Force
$upn = $i.id + "@ehs.ucsb.edu"
new-QADUser -Password $ss -UserPrincipalName $upn -name $i.fullname -OrganizationalUnit $ou -SamAccountName $i.id -FirstName $i.firstname -LastName $i.lastname -Displayname $i.fullname -Department $i.department -Title $i.title -PhoneNumber $i.phone
}



I actually would like to get the password situation worked out with the NewQADUser script above as opposed to the new-mailbox script, but the password issue is the same with both scripts.

Thanks,
alex




Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Password Import Issues into AD from CSV file
Posted: Nov 30, 2009 1:38 AM   in response to: amook_250
 
  Click to reply to this thread Reply

The code looks ok to me, can you test it again:


$data = Import-CSV c:\import.csv
$mdb = 'EX07SP1\Mailbox Database'
$ou = 'litwareinc.com/Users'

ForEach ($i in $data)
{
 $ss = ConvertTo-SecureString $i.password -asPlaintext -Force
 $upn = $i.id + "@ehs.com"
 New-Mailbox -Password $ss -Database $mdb -UserPrincipalName $upn -name $i.fullname -OrganizationalUnit $ou -SamAccountName $i.id -FirstName $i.firstname -LastName $i.lastname -Displayname $i.fullname
}



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

Posts: 3
Registered: 11/19/09
Re: Password Import Issues into AD from CSV file
Posted: Nov 30, 2009 2:50 PM   in response to: Shay Levy
 
  Click to reply to this thread Reply

Hi Shay,

I acutally ran a similar script as this is what I decided I need to run. Instead of the new-mailbox command I am running the new-QADuser command. I can create mailboxes later after the user is created. I am still having a problem with the password part though. The account gets created no problem but a password does not get created. Below is the output after the script is run. Here is an example from the csv file...

ID,fullname,LastName,FirstName,Password,title,department, Phone
john.doe,John Doe, Doe, Jon,dfkew#1, Manager, Human Resources,805-989-3433


Here is my code:

# Set up variables

$data = Import-CSV c:\import.csv
$ou = 'litwareinc.com/Users'

#Import the data and create the new mailboxes

ForEach ($i in $data)
{
$ss = ConvertTo-SecureString $i.password -AsPlainText -Force
$upn = $i.id + "@ehs.ucsb.edu"
##also try firstname . lastname
new-QADUser -Password $ss -UserPrincipalName $upn -name $i.fullname -OrganizationalUnit $ou -SamAccountName $i.id -FirstName $i.firstname -LastName $i.lastname -Displayname $i.fullname -Department $i.department -Title $i.title -PhoneNumber $i.phone
}





Here is the output of the script:



Name                           Type            DN
----                           ----            --
John Doe                       user            CN=John Doe,CN=Users,DC=LITWA...

ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it
is null.
At C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\6a4b55df-de08-4fe2-b8c4-680f6a2eba57.ps1:
10 char:29
+ $ss = ConvertTo-SecureString  <<<< $i.password -AsPlainText -Force
New-QADUser : The argument cannot be null or empty.
At C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\6a4b55df-de08-4fe2-b8c4-680f6a2eba57.ps1:
13 char:56
+ new-QADUser -Password $ss -UserPrincipalName $upn -name  <<<< $i.fullname -Or
ganizationalUnit $ou -SamAccountName $i.id -FirstName $i.firstname -LastName $i
.lastname -Displayname $i.fullname -Department $i.department -Title $i.title -P
honeNumber $i.phone
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it
is null.
At C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\6a4b55df-de08-4fe2-b8c4-680f6a2eba57.ps1:
10 char:29
+ $ss = ConvertTo-SecureString  <<<< $i.password -AsPlainText -Force
New-QADUser : The argument cannot be null or empty.
At C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\6a4b55df-de08-4fe2-b8c4-680f6a2eba57.ps1:
13 char:56
+ new-QADUser -Password $ss -UserPrincipalName $upn -name  <<<< $i.fullname -Or
ganizationalUnit $ou -SamAccountName $i.id -FirstName $i.firstname -LastName $i
.lastname -Displayname $i.fullname -Department $i.department -Title $i.title -P
honeNumber $i.phone
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it
is null.
At C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\6a4b55df-de08-4fe2-b8c4-680f6a2eba57.ps1:
10 char:29
+ $ss = ConvertTo-SecureString  <<<< $i.password -AsPlainText -Force
New-QADUser : The argument cannot be null or empty.
At C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\6a4b55df-de08-4fe2-b8c4-680f6a2eba57.ps1:
13 char:56
+ new-QADUser -Password $ss -UserPrincipalName $upn -name  <<<< $i.fullname -Or
ganizationalUnit $ou -SamAccountName $i.id -FirstName $i.firstname -LastName $i
.lastname -Displayname $i.fullname -Department $i.department -Title $i.title -P
honeNumber $i.phone


PS C:\>




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