Help Please, if you dare! (info inside since title sucks)

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Gerg Utubr Gerg Utubr 11 months, 1 week ago.

  • Author
  • #32226
    Profile photo of Gerg Utubr
    Gerg Utubr

    The following is a script I'm trying to put together that
    takes in a list of users from a database file and adds them as users into the active directory. Also omits duplicates. I'll comment where I know issues reside, I'm hoping you'll be kind enough to help me get it to work since PS errors don't help me much I'm a noob.

    Import-Module ActiveDirectory

    $newUserList = Import-Csv C:\Users\Administrator\Desktop\dbs\Monday.csv

    ForEach ($item in $newUserList){
    $fname = $($item.first_name)
    $lname = $($item.last_name)
    $phone = $($item.phone1)
    #I know everything works up to this point.


    # Puts Domain name into a Placeholder.


    # Build the User Principal Name Username with Domain added to it


    # Create the Displayname

    $Name=$fname+” “+$lname

    # Create User in Active Directory FIRST issue resides here, PS doesn't understand the following cmdlets, it misinterprets them all as objects. I assume none of it works but I'm especially unsure of the TelephoneNumber as I just guessed on that one:

    $newusers1 = (NEW-QADUSER –FirstName $fname –Lastname $lname -Telephonenumber $phone –Name $DisplayName $Name –SamAccountName $username –UserPassword '1NewPassword' –UserPrincipalName $UPN –Name $Name –ParentContainer 'csilab.local')


    #THE FOLLOWING CODE TAKES USERS IN newusers1 VAR AND PUTS THEM IN AD ACTIVE USERS GROUP. I haven't tested this as script isn't even making accounts yet. However I know this code section works.

    get-AdUser $newusers1 | Move-ADObject -TargetPath 'OU=Active Users, dc=csilab, dc=local'
    Add-ADGroupMember -Identity "Active Users Security" -Members $newusers1

    #REMOVES ANY DUPLICATES IN AD THAT GET PAST THE SORTING CODE IN DB FILE IMPORT SECTION. I want it to both confirm same name AND phone number since it's unlikely you'll have two people with both matching. Whereas two people with the same name is possible.

    (get-AdGroupMember "Active Users Security") | Remove-ADUser -Identity 'SamAccountName' 'SamTelephoneNumber' IncludeEqual -confirm:$false

    #Error checking component, ignore if it doesn't work, even with a variable I couldn't get this to work

    if($error -eq 0)

    write-host "Thank you, the users have been added to the directory successfully."
    $b1 = Read-Host ('dddd')

    if($error -eq 1)

    write-host "UNEXPECTED ERROR:" -ForegroundColor Red
    $b1 = Read-Host ('dddd')

    #Thank you for your time... I know this is a mess.

  • #32228
    Profile photo of Curtis Smith
    Curtis Smith

    To use the "Quest AD User" (new-qaduser) cmdlets (now owned by Dell), you need to have the quest cmdlets installed ( They are not native in PowerShell.

    I would probably recommend switching over and using the Microsoft activedirectory module cmdlets. New-ADUser instead of New-QADUser.

  • #32230
    Profile photo of Curtis Smith
    Curtis Smith
  • #32231
    Profile photo of Gerg Utubr
    Gerg Utubr

    Thanks Curtis, I'll switch that out as you suggested and see what happens.

You must be logged in to reply to this topic.