- Courses
- đź’»Programming Languages
- 🪟PowerShell
- PowerShell for System Administration
- Managing Windows Systems
- Local Users and Groups
On this page
PowerShell Local Users and Groups Management
Updated on June 19, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
Local users and groups form the foundation of identity and access control on Windows systems. PowerShell provides a structured, predictable, and scriptable interface for managing these accounts through the Microsoft.PowerShell.LocalAccounts module. Administrators can create users, modify group membership, enforce security policies, and audit access configurations without relying on graphical tools, enabling consistent and repeatable administration across standalone and domain-joined machines.
Understanding Local Accounts and Groups​
Windows maintains two layers of identity: local accounts stored on the individual machine, and domain accounts stored in Active Directory (if the machine is domain-joined). Local accounts are used for:
- Administrative access to standalone systems
- Break-glass access when domain authentication is unavailable
- Running scheduled tasks or services under controlled identities
- Managing workgroup environments
Local groups provide a way to assign permissions to multiple users at once. Key local groups include:
GroupPurposeAdministratorsFull control over the systemUsersStandard user privilegesRemote Desktop UsersPermission to sign in via RDPBackup OperatorsAbility to back up and restore filesRemote Management UsersPermission to manage the system remotely
PowerShell exposes these accounts and groups as objects, allowing you to inspect and modify them programmatically.
PowerShell Tools for Managing Local Accounts​
The Microsoft.PowerShell.LocalAccounts module provides a comprehensive set of cmdlets for local user and group management. To see all available cmdlets:
Get-Command -Module Microsoft.PowerShell.LocalAccounts
Code explanation: This command lists every cmdlet in the LocalAccounts module, showing all available verbs and nouns for local user and group management.
The module includes 15 cmdlets covering every aspect of local account administration:
CmdletPurposeGet-LocalUserGets local user accountsNew-LocalUserCreates a local user accountSet-LocalUserModifies a local user accountRename-LocalUserRenames a local user accountEnable-LocalUserEnables a disabled user accountDisable-LocalUserDisables a user accountRemove-LocalUserRemoves a user accountGet-LocalGroupGets local security groupsNew-LocalGroupCreates a local security groupSet-LocalGroupModifies a local groupRename-LocalGroupRenames a local groupRemove-LocalGroupRemoves a local groupGet-LocalGroupMemberGets members of a local groupAdd-LocalGroupMemberAdds a member to a local groupRemove-LocalGroupMemberRemoves a member from a local group
Important: The Microsoft.PowerShell.LocalAccounts module is not available in 32-bit PowerShell on a 64-bit system. Always run PowerShell in 64-bit mode when using these cmdlets.
Inspecting Local Users​
Retrieving All Local Users​
To list every local user account on the system:
Get-LocalUser
Code explanation: This returns objects representing each user, including properties such as Name, Enabled status, Password expires, Account expires, and Description.
Inspecting a Specific User​
To examine the configuration of a particular account:
Get-LocalUser -Name "Administrator"
This allows you to check whether the account is enabled, when the password was last set, and other security-relevant properties.
Filtering by Account Properties​
To find all disabled accounts:
Get-LocalUser | Where-Object { $_.Enabled -eq $false }
To find accounts with passwords that never expire:
Get-LocalUser | Where-Object { $_.PasswordNeverExpires -eq $true }
Accounts with non-expiring passwords should be reviewed carefully as they represent a security risk.
Creating and Managing Local Users​
Creating a New User​
To create a new local user with a secure password:
$password = Read-Host "Enter password" -AsSecureString
New-LocalUser -Name "MaintenanceUser" -Password $password -Description "Account for scheduled maintenance tasks"
Code explanation: Read-Host -AsSecureString prompts for a password without displaying it in plain text. The password is stored as a SecureString object and passed to New-LocalUser, ensuring it is not exposed in the script.
To create a user with no password (not recommended for production):
New-LocalUser -Name "TempUser" -NoPassword -Description "Temporary account"
To create a user with an account that never expires:
New-LocalUser -Name "ServiceAccount" -AccountNeverExpires -Password $password
Enabling or Disabling Accounts​
Disabling accounts is a common security practice when an account is temporarily not needed:
Disable-LocalUser -Name "MaintenanceUser"
Enable-LocalUser -Name "MaintenanceUser"
Setting or Resetting Passwords​
To update a user's password while preserving the rest of the account configuration:
$password = Read-Host "Enter new password" -AsSecureString
Set-LocalUser -Name "MaintenanceUser" -Password $password
To configure a password to never expire:
Set-LocalUser -Name "MaintenanceUser" -PasswordNeverExpires $true
To allow the user to change their own password:
Set-LocalUser -Name "MaintenanceUser" -UserMayChangePassword $true
Renaming a User​
Rename-LocalUser -Name "OldUsername" -NewName "NewUsername"
Inspecting Local Groups​
Listing All Local Groups​
Get-LocalGroup
This returns groups such as Administrators, Users, Remote Desktop Users, and Guests.
Inspecting a Specific Group​
Get-LocalGroup -Name "Administrators"
This retrieves the group definition, including its description and security identifier (SID).
Creating a New Local Group​
New-LocalGroup -Name "AppServer_Operators" -Description "Members can restart app services but have no admin rights"
Managing Group Membership​
Group membership determines what users can do on the system. PowerShell provides explicit commands for modifying membership.
Viewing Group Members​
Get-LocalGroupMember -Group "Administrators"
This reveals which accounts—local or domain—have administrative privileges.
Adding a User to a Group​
Add-LocalGroupMember -Group "Administrators" -Member "MaintenanceUser"
Code explanation: This grants the user administrative rights by adding them to the Administrators group. The -Member parameter accepts local users, domain users (in DOMAIN\username format), Microsoft accounts, and Microsoft Entra accounts.
To add multiple members at once:
Add-LocalGroupMember -Group "Administrators" -Member "User1", "User2", "User3"
Removing a User from a Group​
Remove-LocalGroupMember -Group "Administrators" -Member "MaintenanceUser"
To remove multiple members:
$members = "User1", "User2", "User3"
Remove-LocalGroupMember -Group "Administrators" -Member $members
Working with Domain Accounts in Local Groups​
Even on domain-joined systems, local groups often contain domain accounts. PowerShell handles this seamlessly.
Adding a Domain User to a Local Group​
Add-LocalGroupMember -Group "Remote Desktop Users" -Member "CONTOSO\jdoe"
This grants the domain user permission to sign in via Remote Desktop.
Adding Domain Groups to Local Groups​
Add-LocalGroupMember -Group "Administrators" -Member "CONTOSO\Domain Admins"
Note: When adding a domain member with the same name as a local user, the domain member takes precedence.
Auditing Local Accounts and Groups​
Regular auditing is essential for maintaining a secure environment.
Identifying Disabled Accounts​
Get-LocalUser | Where-Object { $_.Enabled -eq $false }
Listing All Local Administrators​
Get-LocalGroupMember -Group "Administrators"
This is one of the most important security checks on any Windows system.
Finding Accounts with Passwords That Never Expire​
Get-LocalUser | Where-Object { $_.PasswordNeverExpires -eq $true }
Auditing All Groups and Their Members​
Get-LocalGroup | ForEach-Object {
$group = $_.Name
Get-LocalGroupMember -Group $group | Select-Object @{N='Group';E={$group}}, Name, ObjectClass
}
Practical Administrative Scenarios​
Creating a Service Account​
$password = Read-Host "Enter password" -AsSecureString
New-LocalUser -Name "ServiceAccount" -Password $password -Description "Local service account" -AccountNeverExpires
Add-LocalGroupMember -Group "Users" -Member "ServiceAccount"
Preparing a Machine for Remote Administration​
Add-LocalGroupMember -Group "Remote Management Users" -Member "CONTOSO\AdminTeam"
Locking Down a System by Auditing Administrators​
Get-LocalGroupMember -Group "Administrators" |
Where-Object { $_.ObjectClass -eq "User" }
This identifies all user accounts with administrative privileges, helping you enforce the principle of least privilege.
Enabling the Built-in Administrator Account​
Get-LocalUser -Name "Administrator" | Enable-LocalUser
Security Considerations and Best Practices​
Principle of Least Privilege: Only grant users the permissions they need. Avoid making all users members of the Administrators group.
Limit Administrator Group Members: Keep the number of users in the Administrators group to a minimum.
Use Dedicated Service Accounts: Create separate accounts for services and scheduled tasks rather than using interactive user accounts.
Audit Regularly: Run the auditing commands above periodically to identify and remediate over-privileged accounts.
Avoid Plaintext Passwords: Always use -AsSecureString with Read-Host or ConvertTo-SecureString when handling passwords in scripts.
Document Account Purpose: Use the -Description parameter when creating accounts to document their purpose for future administrators.
Consider Group Managed Service Accounts: For domain-joined systems, gMSA provides passwordless service account management and eliminates credential rotation concerns.
Summary​
Local users and groups form the backbone of access control on Windows systems. PowerShell provides a clear, structured, and scriptable interface for managing them, enabling administrators to:
- Inspect and create local accounts
- Modify passwords and enable or disable accounts
- Inspect and manage local groups
- Control group membership with precision
- Integrate domain accounts into local security structures
- Audit access configurations for security and compliance
By mastering these tools, you gain fine-grained control over identity and permissions on Windows systems, enabling secure and consistent administrative practices.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Scheduled Tasks
Next
WMI and CIM
-
Understanding Local Accounts and Groups
-
PowerShell Tools for Managing Local Accounts
-
Inspecting Local Users
- Retrieving All Local Users
- Inspecting a Specific User
- Filtering by Account Properties
-
Creating and Managing Local Users
- Creating a New User
- Enabling or Disabling Accounts
- Setting or Resetting Passwords
- Renaming a User
-
Inspecting Local Groups
- Listing All Local Groups
- Inspecting a Specific Group
- Creating a New Local Group
-
Managing Group Membership
- Viewing Group Members
- Adding a User to a Group
- Removing a User from a Group
-
Working with Domain Accounts in Local Groups
- Adding a Domain User to a Local Group
- Adding Domain Groups to Local Groups
-
Auditing Local Accounts and Groups
- Identifying Disabled Accounts
- Listing All Local Administrators
- Finding Accounts with Passwords That Never Expire
- Auditing All Groups and Their Members
-
Practical Administrative Scenarios
- Creating a Service Account
- Preparing a Machine for Remote Administration
- Locking Down a System by Auditing Administrators
- Enabling the Built-in Administrator Account
-
Security Considerations and Best Practices
-
Summary
