forked from internal/ActiveDirectory
23 lines
1003 B
Plaintext
23 lines
1003 B
Plaintext
# Import the Active Directory module
|
|
Import-Module ActiveDirectory
|
|
|
|
# Define source and destination attribute names as variables
|
|
$sourceAttribute = "personalTitle"
|
|
$destinationAttribute = "extensionAttribute1"
|
|
|
|
# Retrieve all users where the source attribute is not empty
|
|
$usersWithSourceAttribute = Get-ADUser -Filter "$sourceAttribute -like '*'" -Properties $sourceAttribute, $destinationAttribute
|
|
|
|
# Loop through each user and update the destination attribute with the source attribute's value
|
|
foreach ($user in $usersWithSourceAttribute) {
|
|
# Extract the value of the source attribute for readability
|
|
$sourceValue = $user.$sourceAttribute
|
|
|
|
try {
|
|
# Copy value from source attribute to destination attribute
|
|
Set-ADUser -Identity $user.DistinguishedName -Replace @{$destinationAttribute = $sourceValue}
|
|
Write-Host "Successfully updated user: $($user.SamAccountName)"
|
|
} catch {
|
|
Write-Host "Failed to update user: $($user.SamAccountName). Error: $_"
|
|
}
|
|
} |