Active Directory - Error - Adding New User

Welcome Forums General PowerShell Q&A Active Directory - Error - Adding New User

Viewing 3 reply threads
  • Author
    Posts
    • #196469
      Participant
      Topics: 1
      Replies: 1
      Points: 16
      Rank: Member

       

      Friends,  I am reading Don Jones' book.  I am new at this.

      We wrote a script to add a user in Active Directory.

      This script works but not with one Attribute,  PersonGUID.

      I am Using a CSV file.  That part works fine.

      Perhaps Active Directory is using another name for PersonGUID.  If so, how can I find that?

      (I am having trouble inserting a screen shot to show you the Attributes.

      And how can I copy and paste the script to keep the line numbers?)

      Here's the error:

      PS C:\WINDOWS\system32> C:\Users\IO.Stephen.Ray\Documents\Add5.ps1

      New-ADUser : A parameter cannot be found that matches parameter name 'PersonGUID'.

      At C:\Users\IO.Stephen.Ray\Documents\Add5.ps1:61 char:13

      +             -PersonGUID $PersonGUID `

      +             ~~~~~~~~~~~

      + CategoryInfo          : InvalidArgument: (:) [New-ADUser], ParameterBindingException

      + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.NewADUser

      And here's the Script,  Line 61 is noted below:

      # Import active directory module for running AD cmdlets

      Import-Module activedirectory

       

      #Store the data from ADUsers.csv in the $ADUsers variable

      $ADUsers = Import-csv C:\Homeuse\add.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

       

      $Username    = $User.username

      $Password    = $User.password

      $Firstname   = $User.firstname

      $Lastname    = $User.lastname

      $OU           = $User.ou #This field refers to the OU the user account is to be created in

      $displayname = $User.displayname

      $streetaddress = $User.streetaddress

      $city       = $User.city

      $zipcode    = $User.zipcode

      $state      = $User.state

      $telephone  = $User.telephone

      $jobtitle   = $User.jobtitle

      $company    = $User.company

      $department = $User.department

      $Password = $User.Password

      $Description = $user.Description

      $PersonGUID = $user.PersonGUID

      $office = $user.office

       

      #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 `

      -SamAccountName $Username `

      -UserPrincipalName "$Username@agencyx.gov" `

      -Name "$Firstname.$Lastname" `

      -GivenName $Firstname `

      -Surname $Lastname `

      -Enabled $True `

      -DisplayName $DisplayName `

      -Path $OU `

      -City $city `

      -Company $company `

      -State $state `

      -StreetAddress $streetaddress `

      -OfficePhone $telephone `

      -Description $description `

      -Title $jobtitle `

      -Department $department `

      -Office $office `

      -postalcode $zipcode `

      -PersonGUID $PersonGUID `

      The line above is line 61.  If I leave this line out, the new record gets created just fine. 

       

       

      -AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True

       

      #Add Smart card required

       

      set-aduser -identity $username -smartcardlogonrequired $True

      Set-ADUser -Identity $username -Replace @{"ExtensionAttribute5"="PROV-O365"}

       

       

       

       

       

       

       

       

      set-Aduser -identity $username -smartcardlogonrequired $True

      Set-ADUser -Identity $username -Replace @{"ExtensionAttribute5"="PROV-O365"}

      Set-ADUser -Identity $username -Replace @{"extensionAttribute3"= $user.extensionAttribute3}

      Set-ADUser -Identity $username -Replace @{"agencyxAgencyAbbreviation"= $user.agencyxAgencyAbbreviation}

      Set-ADUser -Identity $username -Replace @{"agencyxOfficeID"=$user.agencyxOfficeID}

      Set-ADUser -Identity $username -Replace @{"c"="US"}

      Set-ADUser -Identity $username -Replace @{"co"="United States"}

      Set-ADUser -Identity $username -Replace @{"countryCode"="840"}

       

       

       

      }

      }

       

       

       

       

       

       

       

    • #196505
      Participant
      Topics: 2
      Replies: 1697
      Points: 3,385
      Helping Hand
      Rank: Community Hero

      Welcome to Powershell.org, Stephen. Please take a little time and read the very first pinned post on top of the list of this forum: Read Me Before Posting! You'll be Glad You Did!. After that please fix your post and format the code as code using the code tag button ("pre") as it is really hard to read this way. If you post error messages or example data you should format this as code as well please. And you should try to avoid to post that much unnecessary whitespace.
      Thanks in advance.

    • #196544
      Participant
      Topics: 1
      Replies: 1
      Points: 16
      Rank: Member

      Olaf,   Indeed!   It is difficult to read with too much white space.  I did read that post.  PowerShell syntax is easier to figure out than how to format a post here.  So far, I am not having any luck.  From Don Jones' Book, I know the syntax and how to distinguish Optional Parameters and Mandatory Parameters and Switch Parameters.  But not this!

    • #196550
      Participant
      Topics: 2
      Replies: 1697
      Points: 3,385
      Helping Hand
      Rank: Community Hero

      ... to figure out than how to format a post here. So far, I am not having any luck.

      You simply mark your code and then klick on code tag button right above the editor window ... it's named "PRE". 😉

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