0
votes

I am looking for a way using Set-ADuser to append a value to the end of an existing attribute.

So far I have: (omitting my filter because of the sensitive nature)

Get-ADUser -Filter (<filter>) -Properties Name,DisplayName,EmployeeID,SAMAccountName | ? {$_.Samaccountname.length -eq 5} | Set-ADUser <???>

I have been looking for a method to append just to the employeeID attribute without overwriting the current value. If there is another way of accomplishing this, I would be interested to know how.

2

2 Answers

0
votes

So, with Set-ADUser you can use the -replace with a hashtable. So run the results through a loop, setup a hashtable on each loop for their EmployeeID to = the existing one plus whatever new text, and set the account to replace the data in the hashtable. Something like this:

Get-ADUser -Filter (<Filter>) |?{$_.SAMAccountName.Length -eq 5} | %{$HT = @{};$HT.add("EmployeeID", "$($_.EmployeeID)AdditionalText");Set-ADUser $_.SAMAccountName -Replace $HT}
0
votes

This will get it done, I tested it and works perfectly:. Just replace info with your desired attribute or property:

Import-Module ActiveDirectory 
$j=Read-Host "Enter the samaccountname" 
$i = Get-ADUser $j -Properties info | %{ $_.info}  
Set-ADUser $j -Replace @{info="$($i) `r`n Account Disabled for O365 Cleanup"} 

Source: https://gallery.technet.microsoft.com/scriptcenter/Powershell-Append-Info-5f613638