Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / PowerShell / Set-ADUser: How to Change User Properties in Active Directory with PowerShell

November 26, 2021 Active DirectoryPowerShell

Set-ADUser: How to Change User Properties in Active Directory with PowerShell

The Set-ADUser cmdlet allows to modify user properties (attributes) in Active Directory using PowerShell. Traditionally, a graphic MMC snap-in dsa.msc (Active Directory Users and Computers, ADUC) is used to edit the properties of AD users. The ADUC snap-in can be used to change user properties or advanced attributes in the Attribute Editor tab. However, you cannot bulk modify user attributes via the ADUC console (it is partially possible to do it using AD saved queries) . In this article, we’ll look at some examples of using the Set-ADUser cmdlet to change user properties in AD.

Contents:
  • Modifying User Properties in Active Directory with PowerShell
  • How to Bulk Modify Active Directory Users Attributes?
  • How to Show User’s Logged on Computer Name in ADUC?

The Set-ADUser cmdlet is part of the Active Directory module for Windows PowerShell and the module must be installed on your computer. On Windows Server, the RSAT-AD-PowerShell module is installed from the Windows features, and on Windows 10 you have to install it from RSAT:

Add-WindowsCapability –online –Name “Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0”

Modifying User Properties in Active Directory with PowerShell

The Get-ADUser cmdlet has about 50 options related to AD attributes (City, Company, Department, Description, EmailAddress, MobilePhone, Organization, UserPrincipalName, etc.). You can display the list of available attributes using the following command:

Get-Help Set-ADUser -Parameter *|ft

Set-ADUser user properties in powershell

The name of a user you want to change AD attributes for is specified in the mandatory Identity option (you can specify it as an sAMAccountName, SID, Distinguished Name or objectGUID).

For example, let’s get the value of the Title attribute of a user using the Get-ADUser cmdlet:

Get-ADUser -Identity M.Becker -Properties title|select-object name,title

Then change its job title in AD:

Set-ADuser M.Becker –title “Junior DevOps Engineer”

Using Set-ADUser PowerShell cmdlet to update user attributes in Active Directory

You can change the values of multiple attributes at once. For example, let’s set a new email address and a list of computers a user is allowed to log on to:

Set-ADUser M.Becker –EmailAddress [email protected] –LogonWorkstations 'munx32f2r13,munx32f2r15'

The following command will disable a user account in the domain:

Set-ADUser M.Becker -Enabled $False

You can change a user photo in AD:

Set-ADUser M.Becker -Replace @{thumbnailPhoto=([byte[]](Get-Content "C:\scripts\ad\m.becker.jpg" -Encoding byte))}

You can edit values of other user attributes (including extensionAttribute and custom attributes) in AD using these Set-ADUser options:

  • Add – adds an attribute value
  • Replace – replaces an attribute value
  • Clear – clears an attribute value
  • Remove — removes one of the attribute values

For example, to change a user phone number, you may use this command:

Set-ADUser M.Becker -MobilePhone $NewNumber

Or:

Set-ADUser M.Becker -replace @{'MobilePhone' = $($Number) }

To add a new value to the extensionAttribute5:

Set-ADUser M.Becker -Add @{extensionAttribute5 = "Test1"}

To clear an attribute value:

Set-ADUser M.Becker -Clear "extensionAttribute5"

You can change values of multiple attributes at a time:

Set-ADUser M.Becker -Replace @{title="Senior DevOps";company="XYZ"}

Also, using these options, you can change multi-valued attributes. For example, let’s add multiple ProxyAddresses (email aliases) to a user:

Set-ADUser M.Becker -add @{ProxyAddresses="smtp:M[email protected], ,SMTP:[email protected] " -split ","}

How to Bulk Modify Active Directory Users Attributes?

You can change the attributes of multiple users at once. For example, the following command will change the value of UserAccountControl attribute and force all users from the specified OU to change their passwords at the next logon:

Get-ADUser -Filter * -SearchBase "OU=Users,OU=DE,DC=woshub,DC=loc" | Set-ADUser -ChangePasswordAtLogon $true

You can bulk update the AD user attributes with the values from a CSV file. For example, you have a CSV file with the list of accounts, titles and phone numbers (the file format is: SamAccountName, Title, MobilePhone).

Modifying Active Directory Users in Bulk using CSV File

To update user attributes using the values from the CSV file, run the following PowerShell command:

Import-Csv "C:\scripts\ad\update_ad_users.csv" | foreach {Set-ADUser -Identity $_.SamAccountName –Title $_.Title -MobilePhone $_.MobilePhone}

You can delegate privileges to update user attributes in AD to an HR employee and even teach them how to work with such CSV/Excel files from PowerShell.

How to Show User’s Logged on Computer Name in ADUC?

In one of the previous articles we showed how to add user information to computer properties in AD using the Set-ADComputer cmdlet. Now let’s consider another approach and try to add information about a computer a user is logged on to the user properties in Active Directory.

To do it, it is enough to add the following PowerShell script to the logon GPO scripts to be run when a user logs on to the computer (User Configuration -> Policies -> Windows Settings -> Scripts -> Logon):

Set-ADUser -identity $env:UserName –Description $env:computername

The script assumes that the PowerShell module for Active Directory is installed on users’ computers. If you don’t want to install RSAT on all computers, you can use the AD PowerShell module without installation by copying its files to all computers using GPO or a logon script.

This will allow you quickly find the name of the computer the user is logged on.

Show user logged on ComputerName In AD

In this example, we save the name of the current computer to the standard Description attribute. You can use another attribute, say one of ExtensionAttributes.

0 comment
0
Facebook Twitter Google + Pinterest
previous post
Windows Defender Threat Service Has Stopped, Restart It Now
next post
Hardening Windows Using Microsoft Security Baselines

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

November 7, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configure Google Chrome Settings with Group Policy
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • How to Find the Source of Account Lockouts in Active Directory
  • How to Disable or Enable USB Drives in Windows using Group Policy
  • Get-ADComputer: Find Computer Properties in Active Directory with PowerShell
  • Configuring Proxy Settings on Windows Using Group Policy Preferences
  • Deploy PowerShell Active Directory Module without Installing RSAT
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top