Solved

Rename multiple domain PCs

Posted on 2011-09-20
13
962 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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 500 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

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.
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

724 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