Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Rename multiple domain PCs

Posted on 2011-09-20
13
Medium Priority
?
1,052 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 7

Expert Comment

by:mmaris
ID: 36568926
0
 
LVL 10

Expert Comment

by:abhijitwaikar
ID: 36569061
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:saddouki
ID: 36569423
@ 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
ID: 36569632
Those two files should be the same name.
0
 

Author Comment

by:saddouki
ID: 36569684
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
 
LVL 13

Expert Comment

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

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

Author Comment

by:saddouki
ID: 36569843
I did, still the same thing
0
 
LVL 13

Expert Comment

by:Govvy
ID: 36569867
Did you replace this line with your domain credentials?

/uD:aaa\myusername /passwordD
0
 

Author Comment

by:saddouki
ID: 36569900
yes :
/uD:MyDomName\mydomainusername /passwordD
0
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 36569959
"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
ID: 36570169
@ 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 2000 total points
ID: 36570589
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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…

604 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