parameter is ambigous

Welcome Forums General PowerShell Q&A parameter is ambigous

Viewing 6 reply threads
  • Author
    Posts
    • #176791
      Participant
      Topics: 17
      Replies: 22
      Points: 210
      Rank: Participant

      Trying to create a bulk user script but get this error

      New-ADUser : Parameter cannot be processed because the parameter name 'Password' is ambiguous. Possible matches include: -PasswordNeverExpires -PasswordNotRequired.

      try {
      Import-Module ActiveDirectory -ErrorAction Stop
      }
      catch {
      Write-host "Missing....Install ActiveDirectory Powershell feature -- RSAT (Remote Server Administration). Cannot Create Accounts" 
      }
      
      #Store the data from ADUsers.csv in the $ADUsers variable
      $ADUsers = Import-csv C:\it\bulk_users1.csv
      
      #Loop through each row containing user details in the CSV file 
      foreach ($User in $ADUsers)
      {
      #Read user data from each field in each row and assign the data to a variable as below
      
      
      $UserProp =@{ 
      Username = $User.username
      Password = $User.password
      Firstname = $User.firstname
      Lastname = $User.lastname
      Path = $User.ou #This field refers to the OU the user account is to be created in
      email = $User.email
      streetaddress = $User.streetaddress
      city = $User.city
      state = $User.state
      country = $User.country
      telephone = $User.telephone
      jobtitle = $User.jobtitle
      company = $User.company
      department = $User.department
      postalcode = $user.zipcode
      userprincipalname = $user.userprincipalname
      group =$user.group
      AccountPassword = (convertto-securestring $user.password -AsPlainText -Force)
      }
      
      
      #Check to see if the user already exists in AD
      if (Get-ADUser -F {SamAccountName -eq $Username})
      {
      #If user does exist, give a warning
      Write-Warning "A user account with username $Username already exist in Active Directory."
      }
      else
      {
      #User does not exist then proceed to create the new user account
      
      #Account will be created in the OU provided by the $OU variable read from the CSV file
      
      New-ADUser @UserProp
      
      }
      
      
      Add-ADGroupMember -identity $group -Members $username -ErrorAction Stop -ErrorVariable CurrentError
      
      } #end for each
    • #176806
      Participant
      Topics: 1
      Replies: 1635
      Points: 3,089
      Helping Hand
      Rank: Community Hero

      You create a parameter "Password" in your $UserProp hashtable but New-ADUser does not have a parameter with this name. It has 2 parameters starting with the word Password.

    • #176812
      Participant
      Topics: 17
      Replies: 22
      Points: 210
      Rank: Participant

      Olaf not sure what you mean.

      My hash table uses "AccountPassword' which is a parameter for new-aduser

    • #176839
      Participant
      Topics: 1
      Replies: 1635
      Points: 3,089
      Helping Hand
      Rank: Community Hero

      Olaf not sure what you mean.

      My hash table uses "AccountPassword' which is a parameter for new-aduser

      AND additionally you create a parameter Password!!! 😉

    • #176842
      Participant
      Topics: 17
      Replies: 22
      Points: 210
      Rank: Participant

      Not understanding olaf...so can anyone else help me?

    • #176854
      Participant
      Topics: 1
      Replies: 1635
      Points: 3,089
      Helping Hand
      Rank: Community Hero

      Could you please take a look at your code snippet and review your $UserProp hashtable. It's this:

      $UserProp = @{ 
          Username = $User.username
          Password = $User.password
          Firstname = $User.firstname
          Lastname = $User.lastname
          Path = $User.ou #This field refers to the OU the user account is to be created in
          email = $User.email
          streetaddress = $User.streetaddress
          city = $User.city
          state = $User.state
          country = $User.country
          telephone = $User.telephone
          jobtitle = $User.jobtitle
          company = $User.company
          department = $User.department
          postalcode = $user.zipcode
          userprincipalname = $user.userprincipalname
          group =$user.group
          AccountPassword = (convertto-securestring $user.password -AsPlainText -Force)
      }

      ... and there you have as the second parameter Password!!! Don't you see this?

      And on the line 51 you pass this to your New-ADUser.

      New-ADUser @UserProp
    • #176869
      Participant
      Topics: 17
      Replies: 22
      Points: 210
      Rank: Participant

      Crap...who put that there. Sorry thought I double checked that.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.