Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Adding PC to Domain and Renaming it in Powershell


  • Please log in to reply
4 replies to this topic

#1 dylandboyer

dylandboyer

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:08:20 PM

Posted 29 June 2017 - 09:20 AM

I am in the process of writing a script that will add a PC to a domain.  I am using the following line to do this. 

 

Add-Computer -ComputerName $env:COMPUTERNAME -NewName $serial -DomainName $domain -Credential $credential 

 

The problem is the computer was previously on the domain and So it is telling me It is unable to rename the computer because the account already exists.

I believe that the script is adding the computer to the domain and then renaming it.  

 

I understand the easiest solution is to delete the PC from AD unfortunately that is not an option.  

 

Is there a way to write this so that I can rename the PC and add it to the domain without restarting in between the 2. 

 

Thanks!



BC AdBot (Login to Remove)

 


#2 GoofProg

GoofProg

  • Banned
  • 224 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:20 PM

Posted 29 June 2017 - 02:32 PM

I think you can rename and add it back to the domain as a new machine.  Now this leaves your old ad entry hanging around.

That is the only solution that I can see if you can only add and not delete.



#3 dylandboyer

dylandboyer
  • Topic Starter

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:08:20 PM

Posted 30 June 2017 - 09:29 AM

I just set it to rename the computer restart and then add it to the domain.  This is the best solution I can come up with at the moment.  



#4 Pimptech

Pimptech

  • Malware Study Hall Senior
  • 251 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Sao Paulo, Brazil
  • Local time:09:20 PM

Posted 17 July 2017 - 11:45 PM

I just set it to rename the computer restart and then add it to the domain.  This is the best solution I can come up with at the moment.  

 

You could rename it and create a script on startup then it can bee add automatically ?



#5 DelPomerinke

DelPomerinke

  • Members
  • 42 posts
  • OFFLINE
  •  
  • Local time:05:20 PM

Posted 21 August 2017 - 06:32 PM

I've added computers to the domain that have previously joined by first performing a Computer reset.

 

https://technet.microsoft.com/en-us/library/cc753596(v=ws.11).aspx






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users