Link to home
Start Free TrialLog in
Avatar of saddouki
saddouki

asked on

Rename multiple domain PCs

I need a script to rename multiple domain computers. The script should be able to read from a text or excel file both old and new name

Thanks
Avatar of Govvy
Govvy
Flag of United States of America image

Avatar of saddouki
saddouki

ASKER

@ Govvy

I am not sure I understand your link script, I am kind of confused by the files names. First a csv files is mentioned then the systems names are saved under in "rename.txt", then another file is added to script $csvfile = "C:\temp\newname.txt" ?

Can you help me undestand ?

Thanks
Those two files should be the same name.
Here what I have done"

1) Create a ps1 file as follow
$csvfile = "C:\temp\newname.txt"
Import-Csv $csvfile | foreach {  
$oldName = $_.OldName;
$newName = $_.NewName;
 
Write-Host "Renaming computer from: $oldName to: $newName"
netdom renamecomputer $oldName /newName:$newName /uD:aaa\myusername /passwordD:* /force /reboot
}

2) Create a rename.txt
OldName,NewName
PC1,PC1N
PC2,PC2N

3)Saved both files in the same location

nothing happens and the .ps1 file opens automatically, what I am doing wrong ?
Change this line: $csvfile = "C:\temp\newname.txt" to:

$csvfile = "C:\temp\rename.txt"
I did, still the same thing
Did you replace this line with your domain credentials?

/uD:aaa\myusername /passwordD
yes :
/uD:MyDomName\mydomainusername /passwordD
"the .ps1 file opens automatically"

Are you double clicking on the PS1 file to execute?  .PS1 is associated with the editor by default, not to execute.

That could be all that's going on here.

Have you tried running the PS1 script from a PowerShell command line?  You'll probably need to enable unsigned local script execution if this is your first go-round with PoSh (I'm just guessing it is).

Hope that helps!
@ netjgrnaut
You got it :) but now I am getting "Invalid option 'renamecomputer' the syntax of this command is NETDOME [options] ..."
ASKER CERTIFIED SOLUTION
Avatar of netjgrnaut
netjgrnaut
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial