Purpose
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:
Publicar un comentario