Error with power shell script RRS feed

  • Question

  • I am tring to run this script but it continues to give me this error 

    FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.NewADUser

    this is the script that I am trying to run

    #Import AD Users with CSV file
    Import-Module ActiveDirectory

    # get teh path to our target CSV
    $filepath = Read-Host -Prompt "Please enter the path of the file"

    # Import the CSV as an array
    $users = Import-Csv $filepath

    # Complete a action for each user in the CSV file
    ForEach ($user in $users) {
        #Do this for each User
        New-ADUser `
            -Name ($user.'First Name' + " " + $user.'Last Name') `
            -GivenName $user.'First Name' `
            -Surname $user.'Last Name' `
            -UserPrincipalName $user.'User Name' `
            -AccountPassword (ConvertTo-SecureString "Winter2018" -AsPlainText -Force) `
            -Description $user. Description `
            -EmailAddress $user.'Email Address' `
            -Title $user.'Job Title' `
            -OfficePhone $user.'Office Phone' `
            -Path $user.'Organizational Unit' `
            -ChangePasswordAtLogon 1 `
            -Enabled ([System.Convert]::ToBoolean($user.Enabled))

    Tuesday, May 14, 2019 3:13 PM


  • Hard to say what the problem might be, but I'd check the UserPrincipalName value you're getting from the CSV's "User Name" column.

    Make sure it's in the format "user@FQDN" and that there are no leading or trailing spaces.

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by ChefKarl1234 Wednesday, May 15, 2019 7:49 PM
    Tuesday, May 14, 2019 3:27 PM