Powershell

Set-ADUser: Modifying Active Directory Users With PowerShell

The cmdlet “Set-ADUser” is utilized to modify the properties or attributes of an Active Directory user in PowerShell. It can update or modify multiple users’ properties simultaneously. It uses the “-Identity” parameter to identify a user by using its distinguished name, security identifier (SID), GUID, or SAMAccountName. Moreover, the stated cmdlet can modify or set the email address of the user.

In this post, the “Set-ADUser” cmdlet will be demonstrated in detail.

Set-ADUser: Modifying Active Directory Users With PowerShell

As described in the above section, the stated cmdlet is responsible for modifying the properties or the attributes of an Active Directory user.

Example 1: Use the “Set-ADUser” Cmdlet to Set the Properties For a User

To set the properties for a specific user, run the provided command:

Set-ADUser -Identity JohnDoe -HomePage 'http://samplewebsite.com/employees/JohnDoe' -LogonWorkstations 'JohnDoe-DSKTOP,JohnDoe-LPTOP'

In the stated code above:

  • First, specify the “Set-ADUser” cmdlet, followed by the “-Identity” parameter having the username value assigned to it.
  • Then, add the “-Homepage” parameter and assign the URL specifying the user details.
  • After that, specify the “-LogonWorkstations” and assign the workstations to it.

Example 2: Use the “Set-ADUser” Cmdlet to Set the Properties For Multiple Users

Use the below-given cmdlet to set the properties for multiple users:

Get-ADUser -Filter 'Name -like "*"' -SearchBase 'OU=HumanResources,OU=UserAccounts,DC=JohnDoe,DC=COM' -Properties DisplayName | % {Set-ADUser $_ -DisplayName ($_.Surname + ' ' + $_.GivenName)}

In the stated code snippet above:

  • First, write the “Get-ADUser” cmdlet followed by the “-Filter” parameter having the stated filter values assigned to it.
  • Then, specify the “-SearchBase” parameter and specify the stated values to it.
  • After that, add another parameter “-Properties” along with the “DisplayName” cmdlet and the “|” pipeline.
  • Lastly, add the modulus operator followed by the “Set-ADUser” cmdlet and the “-DisplayName” parameter.

Example 3: Use the “Set-ADUser” Cmdlet to Set Properties For E-Mail Address

If you want to set the properties for email, provided command can be used:

Set-ADUser -Identity JamesBen -Replace @{title="director";mail="[email protected]"}

According to the above code snippet:

  • First, specify the “Set-ADUser”, followed by the “-Identity” parameter having the value “JamesBen” which is a username assigned to it.
  • Then, write the “-Replace” parameter and specify the stated hash-table above.

Example 4: Use the “Get-ADUser” Cmdlet to Get a User and the “Set-ADUser” Cmdlet to Set a Property

In this code illustration, first, the user will be retrieved, and then it can be set as a new user:

Get-ADUser -Identity "JamesBen" | Set-ADUser -Manager "JohnDoe"

In the above code snippet:

  • First, define the “Get-ADUser” cmdlet, followed by the “-Identity” parameter and assign the existing username and add the pipeline “|”.
  • After that, specify the “Set-ADUser” cmdlet along with the “-Manager” parameter and assign the new user by assigning the username.

That’s all about the PowerShell “Set-ADUser” cmdlet.

Conclusion

The “Set-ADUser” cmdlet modifies the Active Directory user attributes or properties. It modifies the commonly used attributes including name, attribute, etc. This post has explained the “Set-ADUser” cmdlet with the aid of various examples.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.