PowerShell Genie

New-ADUser

Use New-ADUser to create an Active Directory user account with identity attributes like -Name, -SamAccountName, -UserPrincipalName, and -AccountPassword.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — New-ADUser

Syntax

1PS> New-ADUser [-Name] <String> [-SamAccountName <String>] [-UserPrincipalName <String>] [-AccountPassword <SecureString>] [-Enabled <Boolean>] [-Path <String>] [-GivenName <String>] [-Surname <String>] [-WhatIf] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

New-ADUser [-Name] <String> [-SamAccountName <String>] [-UserPrincipalName <String>] [-AccountPassword <SecureString>] [-Enabled <Boolean>] [-Path <String>] [-GivenName <String>] [-Surname <String>] [-WhatIf] [<CommonParameters>]
  1. Stage 1New-ADUser-Name -SamAccountName -UserPrincipalName -AccountPassword -Enabled -Path -GivenName -Surname -WhatIf

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    New-ADUser with a secure password

    1PS> $p = Read-Host "Enter password" -AsSecureString
    2PS> New-ADUser -Name "Jane Smith" -SamAccountName jsmith -UserPrincipalName jsmith@corp.local -AccountPassword $p -Enabled $true -Path "OU=Sales,DC=corp,DC=local" -PassThru
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Name       SamAccountName UserPrincipalName Enabled
    ----       -------------- ----------------- -------
    Jane Smith jsmith         jsmith@corp.local True

    Note: New-ADUser is silent on success — without -PassThru it prints nothing. -PassThru returns the new user object so you can confirm it was created.

    Get-ADUser -Filter 'SamAccountName -eq "jsmith"'

    1PS> Get-ADUser -Filter 'SamAccountName -eq "jsmith"' # confirm it exists
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Name        SamAccountName  Enabled
    ----------  --------------  -------
    Jane Smith  jsmith          True

    Parameters

    Parameter definitions:

    • -Name
    • -SamAccountName
    • -UserPrincipalName
    • -AccountPassword
    • -Enabled
    • -Path
    • -GivenName
    • -Surname
    • -WhatIf

    New-ADUser on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use New-ADUser when you need to create an Active Directory user account with identity attributes like -Name, -SamAccountName, -UserPrincipalName, and -AccountPassword. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: A duplicate account-name error needs checking existing directory objects. Resolve the intended user and use an update workflow when the account already exists rather than generating an arbitrary new identity. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Set-ADUser. New-ADUser creates a user object; Set-ADUser changes an existing one. Creation settings and subsequent account updates should be reviewed separately in a bulk provisioning workflow. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    New-ADUser reference on Microsoft Learn

    Recap

    New-ADUser Use New-ADUser to create an Active Directory user account with identity attributes like -Name, -SamAccountName, -UserPrincipalName, and -AccountPassword.

    Next: Remove-ADUser
    Genie guideNew-ADUser

    Use New-ADUser to create an Active Directory user account with identity attributes like -Name, -SamAccountName, -UserPrincipalName, and -AccountPassword. The console below is pre-loaded — run it, then change a value and run it again.