- Courses
- 💻Programming Languages
- 🪟PowerShell
- PowerShell for System Administration
- Active Directory
- Creating and Modifying Users, Groups and Computers
On this page
Creating and Modifying Users, Groups and Computers with PowerShell
Updated on June 22, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
The ActiveDirectory module provides a comprehensive set of cmdlets for creating and modifying AD objects. New-ADUser, New-ADGroup, and New-ADComputer handle object creation with required attributes such as Name, SamAccountName, and Path for OU placement. Set-ADUser, Set-ADGroup, and Set-ADComputer enable attribute updates, while Set-ADAccountPassword handles password resets and Enable-ADUser/Disable-ADUser control account state. Group membership is managed with Add-ADGroupMember and Remove-ADGroupMember. Computer pre‑staging uses New-ADComputer to create objects before domain join. Bulk operations are efficiently handled by importing CSV data and iterating with ForEach-Object. Mastering these cmdlets enables consistent, scalable identity administration across the enterprise.
Creating and Managing AD Users
User accounts represent individuals or service identities within the domain. PowerShell provides New-ADUser, Set-ADUser, and Enable-ADUser/Disable-ADUser for managing them.
Creating a New User
Creating a user requires specifying at least a name and a security principal. In most organizations, additional attributes such as department, email, or office location are also required.
Example: Creating a Basic User
$password = Read-Host "Enter password" -AsSecureString
New-ADUser `
-Name "Enrico Rossi" `
-GivenName "Enrico" `
-Surname "Rossi" `
-SamAccountName "enrico.rossi" `
-UserPrincipalName "[email protected]" `
-AccountPassword $password `
-Enabled $true
Code explanation: Read-Host -AsSecureString securely captures the password without displaying it in plain text. New-ADUser creates the user object with the specified attributes. The -AccountPassword parameter sets the initial password, and -Enabled $true activates the account immediately. The user is created in the default Users container unless a different OU is specified with -Path.
Creating a User in a Specific OU
New-ADUser -Name "John Doe" -SamAccountName "jdoe" `
-Path "OU=Sales,DC=contoso,DC=com"
Code explanation: The -Path parameter specifies the distinguished name of the target OU, ensuring the user is placed in the correct organizational unit.
Modifying Existing Users
Once a user exists, attributes can be updated using Set-ADUser.
Updating User Attributes
Set-ADUser -Identity "enrico.rossi" -Department "IT" -Office "Tokyo"
Code explanation: Set-ADUser updates the specified attributes for the user identified by the -Identity parameter. The -Identity parameter accepts a username, distinguished name, GUID, or SID.
Setting or Resetting a Password
Set-ADAccountPassword -Identity "enrico.rossi" -NewPassword $password
Code explanation: Set-ADAccountPassword changes the password for the specified account. The -NewPassword parameter requires a secure string. After a password reset, the account may need to be enabled if it was disabled.
Enabling or Disabling a User
Disable-ADUser -Identity "jdoe"
Enable-ADUser -Identity "jdoe"
Code explanation: Disable-ADUser prevents the account from being used for authentication while preserving its configuration. Enable-ADUser reverses this, allowing the account to be used again. Disabling accounts is a common practice when employees leave the organization.
Creating and Managing AD Groups
Groups are essential for assigning permissions and managing access. PowerShell provides New-ADGroup, Set-ADGroup, and membership cmdlets such as Add-ADGroupMember.
Creating a New Group
Groups can be security groups (used for permissions) or distribution groups (used for email lists).
Example: Creating a Security Group
New-ADGroup `
-Name "Helpdesk" `
-SamAccountName "Helpdesk" `
-GroupScope Global `
-GroupCategory Security `
-Path "OU=Groups,DC=contoso,DC=com"
Code explanation: New-ADGroup creates a new group object. -GroupScope defines the group's scope: Global, DomainLocal, or Universal. -GroupCategory specifies whether the group is Security or Distribution. -Path places the group in the appropriate OU.
Modifying Groups
Updating Group Attributes
Set-ADGroup -Identity "Helpdesk" -Description "Tier 1 support team"
Code explanation: Set-ADGroup updates the attributes of an existing group. The -Description parameter adds or updates the group's description.
Adding Members to a Group
Add-ADGroupMember -Identity "Helpdesk" -Members "jdoe","enrico.rossi"
Code explanation: Add-ADGroupMember adds one or more members to a group. The -Members parameter accepts an array of distinguished names, SAM account names, or GUIDs.
Removing Members
Remove-ADGroupMember -Identity "Helpdesk" -Members "jdoe" -Confirm:$false
Code explanation: Remove-ADGroupMember removes specified members from a group. The -Confirm:$false parameter suppresses the confirmation prompt, which is useful in automation scripts.
Retrieving Group Membership
Get-ADGroupMember -Identity "Helpdesk"
Code explanation: Get-ADGroupMember returns users, groups, and service accounts that belong to the specified group.
Creating and Managing AD Computer Objects
Computer objects represent domain-joined machines. They store information such as the machine's name, operating system, and last logon time.
Creating a Computer Object
Computer objects are often created automatically when a machine joins the domain, but administrators sometimes pre-stage them.
Example: Creating a Computer Object
New-ADComputer `
-Name "PC-01" `
-SamAccountName "PC-01$" `
-Path "OU=Workstations,DC=contoso,DC=com"
Code explanation: New-ADComputer creates a computer object in AD. Computer SAM account names end with a dollar sign ($). Pre-staging ensures the computer is placed in the correct OU before it joins the domain, enabling proper Group Policy application at first boot.
Modifying Computer Objects
Updating Computer Attributes
Set-ADComputer -Identity "PC-01" -Description "Marketing workstation"
Code explanation: Set-ADComputer updates attributes of a computer object. The -Description parameter adds a description to the computer account.
Moving a Computer to a Different OU
Move-ADObject `
-Identity "CN=PC-01,OU=Workstations,DC=contoso,DC=com" `
-TargetPath "OU=Marketing,DC=contoso,DC=com"
Code explanation: Move-ADObject moves an object to a different container or OU. The -Identity parameter requires the full distinguished name of the object, and -TargetPath specifies the destination OU. This is common when reorganizing departments or applying different Group Policies.
Practical Administrative Scenarios
Creating a New Employee Account with Group Membership
$password = Read-Host "Enter password" -AsSecureString
New-ADUser `
-Name "Alice Kim" `
-SamAccountName "alice.kim" `
-UserPrincipalName "[email protected]" `
-AccountPassword $password `
-Enabled $true `
-Path "OU=Employees,DC=contoso,DC=com"
Add-ADGroupMember -Identity "Employees" -Members "alice.kim"
Code explanation: This script creates a new user account with a secure password, enables it, places it in the Employees OU, and adds the user to the Employees group in a single workflow. This pattern is typical for onboarding automation.
Bulk-Creating Users from a CSV File
$users = Import-Csv "C:\NewUsers.csv"
foreach ($u in $users) {
New-ADUser `
-Name $u.Name `
-SamAccountName $u.SamAccountName `
-UserPrincipalName $u.UserPrincipalName `
-AccountPassword (ConvertTo-SecureString $u.Password -AsPlainText -Force) `
-Enabled $true `
-Path $u.OU
}
Code explanation: Import-Csv reads user data from a CSV file. The foreach loop processes each row, creating a user with attributes from the CSV. ConvertTo-SecureString -AsPlainText -Force converts the plain text password from the CSV to a secure string. This approach scales to hundreds or thousands of users.
Security Note: Storing plaintext passwords in CSV files is a security risk. In production, use encrypted credential files, Azure Key Vault, or other secrets management solutions.
Moving All Disabled Computers to a Specific OU
Get-ADComputer -Filter "Enabled -eq 'False'" |
Move-ADObject -TargetPath "OU=DisabledComputers,DC=contoso,DC=com"
Code explanation: Get-ADComputer retrieves all disabled computer objects. Each object is piped to Move-ADObject, which moves it to the DisabledComputers OU. This helps organize stale computer accounts for review and cleanup.
Resetting a User's Password and Forcing Change at Next Logon
$newPassword = Read-Host "Enter new password" -AsSecureString
Set-ADAccountPassword -Identity "jdoe" -NewPassword $newPassword -Reset
Set-ADUser -Identity "jdoe" -ChangePasswordAtLogon $true
Code explanation: Set-ADAccountPassword with the -Reset parameter forces a password reset. Set-ADUser with -ChangePasswordAtLogon $true sets the flag that requires the user to change their password at the next logon.
Creating a Group with Multiple Members from a CSV
$members = Import-Csv "C:\GroupMembers.csv"
$groupName = "ProjectAlpha"
foreach ($m in $members) {
Add-ADGroupMember -Identity $groupName -Members $m.SamAccountName
}
Code explanation: This script reads a list of SAM account names from a CSV and adds each as a member to the specified group. This is useful for bulk group membership updates.
Summary
PowerShell provides a comprehensive and structured interface for creating and modifying Active Directory objects. With the AD module, you can:
- Create users with secure passwords and detailed attributes using
New-ADUser - Modify user properties, reset passwords, and enable or disable accounts with
Set-ADUser,Set-ADAccountPassword,Enable-ADUser, andDisable-ADUser - Create and manage security and distribution groups with
New-ADGroupandSet-ADGroup - Add or remove group members with precision using
Add-ADGroupMemberandRemove-ADGroupMember - Pre-stage and update computer objects with
New-ADComputerandSet-ADComputer - Move objects between OUs with
Move-ADObject - Automate large-scale identity operations using scripts and CSV imports
Mastering these cmdlets allows you to manage Active Directory efficiently, consistently, and safely—whether you are onboarding new employees, maintaining group memberships, or organizing computer objects across the domain.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Querying AD Objects
Next
PowerShell Scripting at Scale
-
Creating and Managing AD Users
- Creating a New User
- Modifying Existing Users
-
Creating and Managing AD Groups
- Creating a New Group
- Modifying Groups
-
Creating and Managing AD Computer Objects
- Creating a Computer Object
- Modifying Computer Objects
-
Practical Administrative Scenarios
- Creating a New Employee Account with Group Membership
- Bulk-Creating Users from a CSV File
- Moving All Disabled Computers to a Specific OU
- Resetting a User's Password and Forcing Change at Next Logon
- Creating a Group with Multiple Members from a CSV
-
Summary
