Scenario: You want to set the Office property for a user account via PowerShell for Active Directory
Solution:
To set a single User for the property Office:
Get-ADUser testusr1 -Properties * | Set-ADObject -Replace @{Office = “test”}
To check a single User for the property Office:
Get-ADUser testusr1 -Properties * | Select name, Office
To clear the value for Office:
Get-ADUser testusr1 -Properties * | Set-ADObject -Clear Office
To set multiple users via script: In the CSV file, have two columns; 1. One column for Name and 2. One column for the Office.
$1 = Import-Csv C:\temp\OfficeDataFile.csv
$1 | %{ $2 = $_.Office; Get-ADUser $_.name -Properties Office | Set-ADObject -Replace @{Office =”$2”} }
To check multiple users via a script
$1 = Import-Csv C:\temp\OfficeDataFile.csv
$1 | %{ Get-ADUser $_.name -Properties Office | Select name, Office}