r/scripting • • Apr 12 '18
[Powershell] - Need help with a rename script
Hi,
The goal of my script is to rename an aduser to have YYMMDD - HOLD - [name].
Currently i have This:
#Input Prompts
$date =get-date
$UserID = Read-Host 'What is users ID?'
#Rename User
$displayname = "$($date.tostring("yyMMdd")) -HOLD- $UserID.name"
Get-ADUser $UserID | Set-ADUser -displayname $displayname -Credential $MyCredentialsIt is renaming the user to 180412 - HOLD - $UserID.name How do I get the existing name :(
3
Upvotes
2
u/yeah_i_got_skills Apr 12 '18
Does this work?
What about this?
2
u/thisisthetechie Apr 12 '18
Not entirely sure of your question.
Get-ADUser $UserId will give you all the data you need about the existing user. If you want to simply get one property, such as displayname, then you can do that with something like: $(Get-ADUser $UserID).Name Get-ADUser $UserID | Select-Object -ExpandProperty Name
1
u/TotesMessenger Apr 12 '18
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)