Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Renaming a Domain Computer with PowerShell

Posted on 2011-09-05
3
Medium Priority
?
1,070 Views
Last Modified: 2012-05-12
Hi all,

I am trying to rename a computer with PowerShell. The script seems to work find when using a workgroup computer, but does not rename a member of a domain.

I am doing:

$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem -Authentication 6
Write-Host "This computer is a member of a domain, and a domain administrator username and password is required"
$domainUsername = Read-Host "Please enter the domain administrator username (in the form DOMAIN\username or username@domain.com"
$domainPassword = Read-Host "Please enter the domain administrator password"
Write-Host "Renaming machine to $newSrvName (member of a domain) ..."
$renameReturn = $ComputerInfo.Rename($newSrvName,$domainPassword,$domainUsername)

However, it is returning error code 1356 (I think that was it from memory) (i.e. $renameReturn = 1356) rather than zero. Renaming from Computer properities is possible with the same credentials.

I think 1356 relates to:

1355 The specified domain either does not exist or could not be contacted.

From: http://www.hiteksoftware.com/knowledge/articles/049.htm

Any help much appreciated.

Regards,

Ben
0
Comment
Question by:webtechy
[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
  • 2
3 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 36488326
try without domain info

$ComputerInfo.Rename($newSrvName)
0
 
LVL 2

Accepted Solution

by:
webtechy earned 0 total points
ID: 36488544
Also posted here:

http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/ad181fe8-dc87-46dd-8ebf-7b1beb0de30d

Solution:

OK, changed script to use:

$creds = Get-Credential

$renameReturn = $ComputerInfo.Rename($newSrvName,$creds.GetNetworkCredential().Password,$creds.Username)

Worked a treat :-) (This script renames a SP server). Only thing is now I guess the machine will also need a new SID still as multiple machines from the same template will exist in the same domain.
0
 
LVL 2

Author Closing Comment

by:webtechy
ID: 36518361
Found resolution
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

730 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