New-ADUser : Access is denied

Marc 631 Reputation points
2022-10-15T21:28:52.59+00:00

I am trying to create a new AD users in Powershell from an Existing User.
I am using the command below:

$newuserattributes = Get-ADUser -Identity 111111 -Properties StreetAddress,City,Title,PostalCode,Office,Department,Manager

New-ADUser -UserPrincipalName "101010" -GivenName Jon -Surname Ford -SAMAccount Name "101010" -Instance $newuserattributes -DisplayName "Jon Ford" -AccountPassword (ConvertTo-SecureString Pas$W0rd!!12 -AsPlainText -Force) -ChangePasswordAtLogon $true -Enabled $false -EmployeeID 101010

Although I am part of the admin group I am getting the error " Access is denied" :

New-ADUser : Access is denied
At line:2 char:1

  • New-ADUser -SAMAccountName "101010" -Instance $userInstance -Name " ...

What elevate credentials do i need to run this command? How can I double check them?

Thanks

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Dillon Silzer 57,831 Reputation points Volunteer Moderator
    2022-10-15T21:53:41.497+00:00

    Hi @Marc

    Please try to elevate PowerShell by running as Administrator:

    250841-image.png

    ----------------------------

    If this is helpful please accept answer.

    1 person found this answer helpful.
    0 comments No comments

  2. Andreas Baumgarten 123.7K Reputation points MVP Volunteer Moderator
    2022-10-15T23:23:03.723+00:00

    Hi @Marc ,

    if you use New-AdUser the user will be created in Active Directory (AD). For this the user who is executing the script needs the permissions in AD to create the user object.
    For instance, the user needs the membership in the Domain Admin or Account Operators group.
    Delegating the permission to create users in AD is an option as well.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  3. Marc 631 Reputation points
    2022-10-16T10:16:07.74+00:00

    I have realised (Get-ADPrincipalGroupMembership username) I am part of "user operators" and not "account operators".

    0 comments No comments

  4. Marc 631 Reputation points
    2022-10-17T15:54:03.333+00:00

    It seems the problem is related with the code: "$newuserattributes = Get-ADUser" because if I create a simple new user (below) the command works. So I have the permissions.

    New-ADUser -Name "User Test" -GivenName User -Surname Test -SamAccountName usertest -UserPrincipalName usertest@test .it -path "OU=Users, DC=test, DC=it"

    I am doing something wrong with the code this is why I am receiving the error " Access is denied".
    How can I create a New AD Users from an Existing User?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.