locked
Bulk import of users via CSV RRS feed

  • Question

  • Hi,

    I am using powershell to add new users to AD via a CSV. I am also using quest powershell cmdlets.

    My input file is as below

    DisplayName

    City

    Company

    Department

    FirstName

    LastName

    Manager

    Office

    PostalCode

    StateOrProvince

    StreetAddress

    JobTitle

    HomeDirectory

    HomeDrive

    Description

    ParentContainer

    SamAccountName

    EndDate

    UPN

    Telephone

    Email

    Test User 3

    Melbourne

    Comp LTD

    IT

    Test

    User3

    Manager

    Melbourne

    3000

    Victoria

    Street Address

    Damager

    \\melb-fs1\testuser3

    H

    Account forTest User 3

    Comp.com/TestUsers

    testuser3

    30/12/2013

    User3@comp.com

    3333 3333

    User3@comp.com

    Test User 4

    Melbourne

    Comp LTD

    IT

    Test

    User4

    Manager

    Melbourne

    3000

    Victoria

    Street Address

    Damager

    \\melb-fs1\testuser4

    H

    Account forTest User 4

    Comp.com/TestUsers

    testuser4

    30/12/2013

    User4@comp.com

    4444 4444

    User4@comp.com

    Test User 5

    Melbourne

    Comp LTD

    IT

    Test

    User5

    Manager

    Melbourne

    3000

    Victoria

    Street Address

    Damager

    \\melb-fs1\testuser5

    H

    Account forTest User 5

    Comp.com/TestUsers

    testuser5

    30/12/2013

    User5@comp.com

    5555 5555

    User5@comp.com

    Test User 6

    Melbourne

    Comp LTD

    IT

    Test

    User6

    Manager

    Melbourne

    3000

    Victoria

    Street Address

    Damager

    \\melb-fs1\testuser6

    H

    Account forTest User 6

    Comp.com/TestUsers

    testuser6


    User6@comp.com

    6666 6666

    When I execute the following code

    Import-Csv c:\Temp\input.csv | ForEach-Object {New-QADUser -Name $_.DisplayName -City $_.City -Company $_.Company -Department $_.Department -FirstName $_.FirstName -LastName $_.LastName -Manager $_.Manager -Office $_.Office -PostalCode $_.PostalCode -StateOrProvince $_.StateOrProvince -StreetAddress $_.StreetAddress -Title $_.JobTitle -HomeDirectory $_.HomeDirectory -HomeDrive $_.HomeDrive -ParentContainer $_.ParentContainer -Description $_.Description -DisplayName $_.DisplayName -SamAccountName $_.SamAccountName -UserPassword "P@ssw0rd" -UserPrincipalName $_.UPN -PhoneNumber $_.Telephone -Email $_.Email | Set-QADUser -UserMustChangePassword  $true -AccountExpires $_.EndDate }

    The code creates the first 3 users, Test User 3, 4 and 5 but throws an error for Test User 6.

    Set-QADUser : Cannot bind parameter 'AccountExpires'. Cannot convert value "" to type "System.DateTime". Error: "String was not 
    recognized as a valid DateTime."

    How can I create a mixture of users, some with end dates and others set to Account Expires to Never???

    • Moved by Bill_Stewart Thursday, January 2, 2014 10:07 PM Unanswerable drive-by question
    Wednesday, December 18, 2013 6:09 AM

Answers

  • Bad file.  You have crap in your file.  The error says it cannot find the value for that column.  It is finding a blank string.  Carefully inspect he file to see what is wrong.

    ¯\_(ツ)_/¯

    • Marked as answer by Sachin Kabbur Monday, April 14, 2014 6:56 AM
    Wednesday, December 18, 2013 6:17 AM