Forum Discussion

charlie4872's avatar
charlie4872
Brass Contributor
Mar 02, 2021
Solved

Adding to end of AD user Samaccountname

Hello I am trying to add a "1_" to the END of a list of Samaccountnames in AD. I found a script that will add it to the BEGINNING of the username but not the end. I have tried moving the 1_$ to then end of the last line but it does not work. Can anyone tell me how I can do this so the new Samaccountname is "aduser_1" instead of "1_aduser"? Below is the script I am using now. Thanks in advance!!

 

$storeusers = Get-Content -Path ".\users.txt"

ForEach ($storeuser in $storeusers) {

$ADuser = Get-ADUser $storeuser
Set-ADUser -Identity $aduser -SamAccountName "1_$($aduser.samaccountname)" -verbose

}

 

  • You dont need to move the 1_$, just move the 1_ and make the code like this
    Set-ADUser -Identity $aduser -SamAccountName "$($aduser.samaccountname)_1" -verbose

2 Replies

  • farismalaeb's avatar
    farismalaeb
    Iron Contributor
    You dont need to move the 1_$, just move the 1_ and make the code like this
    Set-ADUser -Identity $aduser -SamAccountName "$($aduser.samaccountname)_1" -verbose

Resources