Users in PowerShell
Get the current user
You can get the current user with the command
$Env:Username
Andrei
List of users
List of local users
Get-LocalUser
Name Enabled Description ---- ------- ----------- Administrator False Built-in account for administering the computer/domain DefaultAccount False A user account managed by the system. defaultuser0 False LAPTOP123-ANDREI True RmAdmin True Guest False Built-in account for guest access to the computer/domain WDAGUtilityAccount False A user account managed and used by the system for Windows Defender Application Guard scenar…
List of administrators
List of admins
Get-LocalGroupMember -Group "Administrators"
ObjectClass Name PrincipalSource ----------- ---- --------------- Group ACCDOM\Domain Admins ActiveDirectory User LAPTOP123\Administrator Local User LAPTOP123\LAPTOP123-ANDREI Local
Create a user
$Password = Read-Host -AsSecureString
Enter the password and press Enter
New-LocalUser "andrei" -Password $Password -FullName "eth1.ru" -Description "Second Admin"
Make sure the new user is now in the list
Get-LocalUser
Name Enabled Description ---- ------- ----------- Administrator False Built-in account for administering the computer/domain andrei True Second Admin DefaultAccount False A user account managed by the system. defaultuser0 False LAPTOP123-ANDREI True RmAdmin True Guest False Built-in account for guest access to the computer/domain WDAGUtilityAccount False A user account managed and used by the system for Windows Defender Application Guard scenar…
Make a user an administrator
Add-LocalGroupMember -Group "Administrators" -Member "andrei"
Access rights
PS C:\Users\AO> notepad permissions.txt
PS C:\Users\AO> Get-Acl -Path "C:\Users\AO\permissions.txt"
Directory: C:\Users\AO\sandbox\powershell Path Owner Access ---- ----- ------ permissions.txt AzureAD\AO NT AUTHORITY\SYSTEM Allow FullControl…
Article author: Andrei Olegovich