Wednesday, 12 Jun 2024

Set-LocalUser: Manage and Update Local User Accounts

The Set-LocalUser cmdlet is a powerful tool that allows you to modify and update local user accounts on your system. Whether you need to reset passwords or change user descriptions, this cmdlet has got you covered.

Modify User Accounts with Set-LocalUser

The Set-LocalUser cmdlet can reset the password of a local user account. This means you can easily update passwords for enhanced security or in case a user forgets their password. But that’s not all; you can also change other details of a user account, such as the account description or full name.

Example 1: Change a Description of a User Account

Set-LocalUser -Name "Admin07" -Description "Description of this account."

In the above example, we use the Set-LocalUser cmdlet to change the description of a user account named Admin07. This allows you to provide a more detailed and informative description for improved user management.

Example 2: Change the Password on an Account

$Password = Read-Host -AsSecureString
$UserAccount = Get-LocalUser -Name "User02"
$UserAccount | Set-LocalUser -Password $Password

In this example, we demonstrate how to change the password for a user account. The first command prompts you for a new password using the Read-Host cmdlet and stores it securely as a string in the $Password variable. The second command retrieves the user account named User02 using the Get-LocalUser cmdlet and stores it in the $UserAccount variable. Finally, the third command updates the password for the user account stored in $UserAccount.

Understanding Parameters

The Set-LocalUser cmdlet accepts various parameters that allow you to customize the behavior according to your requirements. Here are some important parameters:

  • -AccountExpires: Specifies an expiration date for the user account.
  • -AccountNeverExpires: Ensures that the user account never expires.
  • -Description: Sets a new description for the user account.
  • -FullName: Updates the full name of the user account.
  • -Name: Specifies the name of the user account to modify.
  • -Password: Sets a new password for the user account.
  • -PasswordNeverExpires: Ensures that the user account’s password never expires.
  • -SID: Specifies the Security Identifier (SID) of the user account.
  • -UserMayChangePassword: Determines if the user is allowed to change their password.
  • -WhatIf: Simulates the execution of the command without making any changes.
  • -Confirm: Prompts for confirmation before executing the command.
Tham Khảo Thêm:  Resetting Your Boost Mobile Voicemail Password

Inputs and Outputs

The Set-LocalUser cmdlet accepts the following inputs:

  • System.Management.Automation.SecurityAccountsManager.LocalUser: You can pipe a local user to this cmdlet.
  • String: You can pipe a string to this cmdlet.
  • SecurityIdentifier: You can pipe a SID to this cmdlet.

This cmdlet does not provide any output.

Notes and Related Links

  • Windows PowerShell provides the following aliases for Set-LocalUser: slu.
  • The PrincipalSource property is a property on LocalUser, LocalGroup, and LocalPrincipal objects that describes the source of the object. The possible sources include:
    • Local
    • Active Directory
    • Microsoft Entra group
    • Microsoft Account

Please note that the PrincipalSource property is supported only by Windows 10, Windows Server 2016, and later versions of the Windows operating system. For earlier versions, the property will be blank.

For more information, check out the following links:

So, with the Set-LocalUser cmdlet at your disposal, managing and updating local user accounts has never been easier. Take control of your system’s user management and ensure the security and efficiency of your operations.