Solved

Rename multiple domain PCs

Posted on 2011-09-20
13
836 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:saddouki
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 13

Expert Comment

by:Govvy
Comment Utility
0
 
LVL 7

Expert Comment

by:mmaris
Comment Utility
0
 
LVL 10

Expert Comment

by:abhijitwaikar
Comment Utility
Check this blog, Michael completed this activity using Excel:
http://dermeph.wordpress.com/2009/03/30/how-to-rename-multiple-computers-in-a-windows-domain/
0
 

Author Comment

by:saddouki
Comment Utility
@ 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
0
 
LVL 13

Expert Comment

by:Govvy
Comment Utility
Those two files should be the same name.
0
 

Author Comment

by:saddouki
Comment Utility
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 ?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Expert Comment

by:Govvy
Comment Utility
Change this line: $csvfile = "C:\temp\newname.txt" to:

$csvfile = "C:\temp\rename.txt"
0
 

Author Comment

by:saddouki
Comment Utility
I did, still the same thing
0
 
LVL 13

Expert Comment

by:Govvy
Comment Utility
Did you replace this line with your domain credentials?

/uD:aaa\myusername /passwordD
0
 

Author Comment

by:saddouki
Comment Utility
yes :
/uD:MyDomName\mydomainusername /passwordD
0
 
LVL 6

Expert Comment

by:netjgrnaut
Comment Utility
"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!
0
 

Author Comment

by:saddouki
Comment Utility
@ netjgrnaut
You got it :) but now I am getting "Invalid option 'renamecomputer' the syntax of this command is NETDOME [options] ..."
0
 
LVL 6

Accepted Solution

by:
netjgrnaut earned 500 total points
Comment Utility
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...
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Do you have users whose passwords are expiring and they are constantly calling you?  Well I sure did and needed a way to put an end to this.  We have a lot of remote users which would not be notified that their passwords were expiring since they wer…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now