Facebook Twitter Instagram
    • Privacy Policy
    • Facebook Page
    • Channel
    • Twitter
    • Sitemap
    Facebook Twitter Instagram
    TechulkTechulk
    • Menu
      • Blogging
      • Android
      • Apps
      • Rooting/Flashing
      • Games
    • How-To
    • Troubleshooting
    • Reviews
    • News
      • Latest
      • Trending
      • Around The Web
    • Affiliate Disclosure
    TechulkTechulk
    Home»Troubleshooting»Add, delete, and modify user accounts and local groups with PowerShell
    Troubleshooting

    Add, delete, and modify user accounts and local groups with PowerShell

    Suryanshu BakshiBy Suryanshu BakshiJuly 14, 2020No Comments4 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp Email
    Share
    Facebook Twitter LinkedIn WhatsApp Pinterest Email

    PowerShell gives the possibility of manage local users with a collection of commands Microsoft.PowerShell.LocalAccounts.

    This article guides you to use Powershell to administer your local accounts and groups.
    How? ‘Or’ What add, delete and modify user accounts and local groups with PowerShell.

    Contents

    • Powershell commands to manage user accounts and groups
    • Add, delete and modify user accounts with PowerShell
      • List local user accounts
      • Create a local user account with PowerShell
      • Change the password of a local user with PowerShell
      • Delete a user account with PowerShell
    • Add, delete and modify user groups with PowerShell
      • List user groups
      • Add a user group with PowerShell
      • Add a user to a local group with Powershell
      • List the user accounts of a user account
      • Delete a local user group in PowerShell
    • Manage users on a remote PC with PowerShell

    Powershell commands to manage user accounts and groups

    Here is the list of commands available to manage local accounts with PowerShell.

    The following command lists them:

    Get-Command -Module Microsoft.PowerShell.LocalAccounts
    Manage local accounts with powershell
    Manage local accounts with powershell
    • Add-LocalGroupMember – Add a user to a group
    • Disable-LocalUser —Deactivate a local user
    • Enable-LocalUser – Activate a local user
    • Get-LocalGroup – View user groups
    • Get-LocalGroupMember – View the list of all groups and their members
    • Get-LocalUser – View local account preferences
    • New-LocalGroup – Create a group
    • New-LocalUser – Create a new local user
    • Remove-LocalGroup – Delete a local user
    • Remove-LocalGroupMember – Remove the member from a group
    • Remove-LocalUser – Delete a local user
    • Rename-LocalGroup – Rename a group
    • Rename-LocalUser – Rename a user
    • Set-LocalGroup – Change the settings of a local group
    • Set-LocalUser – Change the settings of a local account

    Add, delete and modify user accounts with PowerShell

    List local user accounts

    Here’s how to list local user accounts.

    Active user accounts are marked True.

    Get-LocalUserList local user accounts in PowerShell

    To display the complete information of a local user account, we use the following Powershell command:

    Get-LocalUser -Name 'username' | Select-Object *
     In place of username, enter the name of the user based of the list of users in your system.
    Get local user by name in Powershell
    Get local user by name in Powershell

    Finally to filter on a particular object we use Select-Object.

    For example the last password modification date:

    Get-LocalUser -Name 'username' | Select-Object PasswordLastSet
    
    Last password modification date
    Last password modification date

    Create a local user account with PowerShell

    Then PowerShell gives the possibility to create the following user accounts:

    • Local accounts
    • Microsoft account
    • Azure Active Directory accounts

    This is done with the command New-LocalUser.

    When you create a user account, you must provide the password.

    Here’s how to create a local account:

    $UserPassword = Read-Host –AsSecureString
    New-LocalUser "Netwrix" -Password $UserPassword -FullName "Username" -Description "CompleteVisibility"

    Below, we created a Microsoft account with Powershell:

    New-LocalUser -Name "MicrosoftAccount[email protected]" -Description "Microsoft Account"

    Finally to create an Azure Active Directory account:

    New-LocalUser -Name "AzureAD[email protected]" -Description "Compte Azure AD"

    Change the password of a local user with PowerShell

    To change the password of a local user account with PowerShell, we use the command Set-LocalUser.

    $UserPassword = Read-Host –AsSecureString
    Set-LocalUser -Name Administrator -Password $UserPassword –Verbose

    So that the password never expires, then use this command:

    Set-LocalUser -Name Username -PasswordNeverExpires $False

    Delete a user account with PowerShell

    The cmdlet Remove-LocalUser allows you to delete a local user account:

    Remove-LocalUser -Name Username -Verbose

    Add, delete and modify user groups with PowerShell

    List user groups

    Here’s how to list user groups with PowerShell:

    Get-LocalGroup
    
    Get localgroup command
    Get localgroup command

    Add a user group with PowerShell

    Then to create a user group, we use New-LocalGroup :

    New-LocalGroup -Name 'NomGroupeUtilisateur' -Description 'Description Groupe utilisateur'

    Add a user to a local group with Powershell

    The command to create a user group is Add-LocalGroupMember.
    You can add multiple users in one command.

    Add-LocalGroupMember -Group 'NomGroupe' -Member ('Username',’Username2') –Verbose

    For example to add the user MaK and SuperMak to the administrator group in PowerShell:

    Add-LocalGroupMember -Group 'Administrateur' -Member ('MaK',’SuperMaK') –Verbose

    List the user accounts of a user account

    To obtain the list of users in a PowerShell group:

    Get-LocalGroupMember -Group 'NomGroupe'List the user accounts of a PowerShell user account

    Delete a local user group in PowerShell

    Finally to delete a local user group in PowerShell, we use Remove-LocalGroupMember :

    Remove-LocalGroupMember -Group 'NomGroupe' -Member 'Username'

    Manage users on a remote PC with PowerShell

    With PowerShell you can also manage users from a remote PC.

    To do this, you must connect to it via WinRM using cmdlets Invoke-Command and Enter-PSSession.

    So it only works with a user domain.

    For example, if we want to remotely view membership in the Local Admin group on multiple computers, we need to run the following script:

    $search = new-pssession -computer NomOrdinateur,NomOrdinateur2,NomOrdinateur3
    invoke-command -scriptblock {Get-LocalGroupMember -Group 'Administrateurs'} -session $search -hidecomputername | select * -exclude RunspaceID | out-gridview -title "Compte Local Admin"
    Share. Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp Email
    Suryanshu Bakshi
    • Facebook
    • Instagram

    He is a geek, casual gamer and a gadget enthusiastic. He has significant knowledge in the field of smartphones along with skills in HTML, Digital Marketing and Photography.

    Related Posts

    FileRepMalware: What is it and how to get rid of it?

    August 19, 2021

    Windows update error 800f0902

    April 22, 2021

    Error code 0x80004004

    February 7, 2021

    Discord screen share audio not working

    September 8, 2020

    How to Resolve Bad System Config Info in Windows 10

    July 13, 2020

    UnLock IT: Delete an Empty Folder, Not Found or Access Denied

    July 12, 2020
    Add A Comment

    Leave A Reply Cancel Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    – Ads –
    Recent Comments
    • Shravan Das on What is CAMRIP, DVDRIP, HDTS, HDTV & other releases?
    • Gumby on What is CAMRIP, DVDRIP, HDTS, HDTV & other releases?
    • ajay kumar on Kerala vision broadband Review & Plans
    • Ravindran on Change Jio fiber login password | Easy Guide 2020
    – Ads –
    Facebook Twitter YouTube Instagram
    • Privacy Policy
    • Facebook Page
    • Channel
    • Twitter
    • Sitemap
    © 2025 Techulk

    Type above and press Enter to search. Press Esc to cancel.