?
Solved

Rename multiple domain PCs

Posted on 2011-09-20
13
Medium Priority
?
1,000 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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

Office 365 Training for Admins - 7 Day Trial

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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