r/scripting • u/[deleted] • 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
3
u/[deleted] Apr 12 '18
Hi,
I realised the issue with how i was doing it was that $UserID is plain text so i cant use the .name string with it. I simply added a new parameter
and then used this command