forked from internal/ActiveDirectory
Add replace-attributes
This commit is contained in:
23
replace-attributes
Normal file
23
replace-attributes
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Import the Active Directory module
|
||||||
|
Import-Module ActiveDirectory
|
||||||
|
|
||||||
|
# Define source and destination attribute names as variables
|
||||||
|
$sourceAttribute = "personalTitle"
|
||||||
|
$destinationAttribute = "msDS-CloudExtensionAttribute1"
|
||||||
|
|
||||||
|
# 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: $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user