viernes, 9 de abril de 2021

WINDOWS. PS. Update and modify extensionAttribute

Purpose

Modifie the Windows user extensionAttribute.

We wan copy the user "company" field in to "extensionAttribute2"

Script

 #Filter all users

$ALLUserTest = get-aduser -filter * -properties *

#Filter some user

#$x = 'Smith'

#$ALLUserTest =Get-ADUser -Filter "SamAccountName -like '*$x*'" -Properties *

 

ForEach($TestUser In $ALLUserTest)

{

   write-host "User: " $TestUser.samaccountname, $TestUser.company

  # Check before

  Get-ADUser  -identity $TestUser.samaccountname -Properties * | Select sAMAccountName, Company, extensionAttribute2 | sort-object -property extensionAttribute2

 #Update fields

                Set-ADUser –Identity $TestUser.samaccountname -Clear "extensionAttribute2"

                Set-ADUser -Identity $TestUser.samaccountname -Add @{extensionAttribute2 = $TestUser.company}

 # Check after

                Get-ADUser  -identity $TestUser.samaccountname -Properties * | Select sAMAccountName, Company, extensionAttribute2 | sort-object -property extensionAttribute2

 

}

 

by GoN | Published: Apr 10, 2021 | Last Updated:

No hay comentarios: