User & Group Management
Users
Account can be categorized as:
Service accounts
Built-in accounts
Administrator(sysadmin tasks on the host)Default(multi-user authentication apps)Guest(disabled by default)WDGUtility(Defender's account)
Local users
Domain users
The management of AD-objects is done via the
ActiveDirectoryPowershell module.Domain users can access any domain-joined host, while local users are restricted only on the host they are created in.
Commands
The
Get,New, andSetverbs are used to find, create, and modify users and groups.LocalUser,LocalGroup,ADUser, andADGroup.
Local
# Listing local (host's) users
Get-LocalUser
# Creating a new local user
New-LocalUser -Name "x7331" -NoPassword
# Adding a password to the user (prompt for entering a password)
$password = Read-Host -AsSecureString
Set-LocalUser -Name "x7331" -Password $password -Description "etile"
# Listing local groups
Get-LocalGroup
# Listing group members
Get-LocalGroupMember -Name "Users"
# Adding a user to the group
Add-LocalGroupMember -Group "Remote Desktop Users" -Member "x7331"Domain
We must first install the ActiveDirectory module which is a part of the Remote System Administration Tools (RSAT).
# Installing all RSAT features, including AD module
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability -Online
# Checking if it's there
Get-Module -Name ActiveDirectory -ListAvailable# Listing AD users
Get-ADUser -Filter *
# Specify an AD user by GUID, objectSid, SamAccountName, or distinguished name
Get-ADUser -Identity x7331
# Filter users based on an attribute
Get-ADUser -Filter {EmailAddress -Like '*domain.com'}
Get-ADUser -Filter {GivenName -eq 'x7331'}
# Creating a new user
New-ADUser -Name "x7332" -Surname "x7333" -GivenName "Mori" -Office "Security" -OtherAttributes @{'title'="Sensei";'mail'="MTanaka@greenhorn.corp"} -Accountpassword (Read-Host -AsSecureString "AccountPassword") -Enabled $true
# Validating the user
Get-ADUser -Identity x7331 -Properties * | Format-Table Name,Enabled,GivenName,Surname,Title,Office,Mail
# Modifying user's description
Set-ADUser -Identity x7331 -Description "the best"Last updated