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

Who is Participating?
netjgrnautConnect With a Mentor Commented:
Hmm.  When I feed NETDOM a bad parameter at the command line, I get...

C:\>netdom blah
The parameter blah was unexpected.

Try "NETDOM HELP" for more information.

I can't force an error like "Invalid option" as you've posted.  What version of Windows are you running the script on?

Copy your command line from your script to a PowerShell window (to mimic execution).  Replace the variables with the first line of your CSV file data.  What happens?  (Copy/sanitize the output, including the command, and post it here.)

Also, typically if you need to specify /UD (because you're not logged on with a domain admin account), you also need to specify /UO.  Not sure that that has anything to do with anything; just thought I'd point it out.

In general, did you know you can execute PowerShell scripts at the PoSh command line, line by line?  It's a great way to troubleshoot script execution.

Let me know how it goes...
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Check this blog, Michael completed this activity using Excel:
saddoukiAuthor Commented:
@ 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 ?

Those two files should be the same name.
saddoukiAuthor Commented:
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

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"
saddoukiAuthor Commented:
I did, still the same thing
Did you replace this line with your domain credentials?

/uD:aaa\myusername /passwordD
saddoukiAuthor Commented:
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!
saddoukiAuthor Commented:
@ netjgrnaut
You got it :) but now I am getting "Invalid option 'renamecomputer' the syntax of this command is NETDOME [options] ..."
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.