locked
Rename multiple computers in Active Directory RRS feed

  • Question

  • I have a script to rename computer in Active directory, and I receive the following error:

    Computer name e033457-cal-ssg cannot be resolved with the exception: No such host is known

    Here is the script:

    $a = Import-Csv ComputerNames.csv -Header OldName, NewName
    Foreach ( $Computer in $a ) {Rename-Computer -ComputerName $Computer.OldName -NewName $Computer.NewName -Force -Restart}

    I am running this from Windows 8.1 machine.  I have a GPO setup with firewall execeptions to allow remote access to domain computers.  Any suggestions would be appreciated.

    Friday, November 20, 2015 5:34 PM

Answers

  • In the workstation GPO:
    Computer Config -> Administrative Templates -> Network Connections -> Windows Firewall -> Domain Profile: Windows Firewall Allow inbound Remote Administration Exception : Enabled

    \_(ツ)_/

    • Proposed as answer by Wendy Jiang Monday, November 23, 2015 8:23 AM
    • Marked as answer by Elaine Jing Monday, December 7, 2015 9:22 AM
    Friday, November 20, 2015 11:51 PM
  • Can your windows 8.1 machine connect to that computer.

    Try to ping the computer see if it pings (or see if it resolve)

    If the pc resolve test the connectivity WinRM port to see if you can remotely run rename-computer

    • Proposed as answer by Wendy Jiang Monday, November 23, 2015 8:22 AM
    • Marked as answer by Elaine Jing Monday, December 7, 2015 9:22 AM
    Friday, November 20, 2015 7:01 PM
  • You need to supply credentials to rename a system.


    \_(ツ)_/

    • Proposed as answer by Wendy Jiang Monday, November 23, 2015 8:22 AM
    • Marked as answer by Elaine Jing Monday, December 7, 2015 9:22 AM
    Friday, November 20, 2015 9:08 PM

All replies

  • Can your windows 8.1 machine connect to that computer.

    Try to ping the computer see if it pings (or see if it resolve)

    If the pc resolve test the connectivity WinRM port to see if you can remotely run rename-computer

    • Proposed as answer by Wendy Jiang Monday, November 23, 2015 8:22 AM
    • Marked as answer by Elaine Jing Monday, December 7, 2015 9:22 AM
    Friday, November 20, 2015 7:01 PM
  • If I ping by name, the name resolves, but the request times out.  I am not sure what you mean by  resolve test the connectivity WinRM port to see if you can remotely run rename-computer.
    Friday, November 20, 2015 7:13 PM
  • I changed the script, and now I get the following error:

    Rename-Computer : Fail to rename computer 'E033457-CAL-SSG' to 'CAL-SSG-E033457' due to the following exception:
    Access is denied.
    At C:\Rename computer.ps1:2 char:30
    + Foreach ( $Computer in $a ) {Rename-Computer -NewName $Computer.NewName -Compute ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (E033457-CAL-SSG:String) [Rename-Computer], InvalidOperationExceptio
        + FullyQualifiedErrorId : FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand

    Here is the new script:

    $a = Import-Csv ComputerNames.csv 
    Foreach ( $Computer in $a ) {Rename-Computer -NewName $Computer.NewName -ComputerName $Computer.Name -Force -Restart}

    Friday, November 20, 2015 8:09 PM
  • You need to supply credentials to rename a system.


    \_(ツ)_/

    • Proposed as answer by Wendy Jiang Monday, November 23, 2015 8:22 AM
    • Marked as answer by Elaine Jing Monday, December 7, 2015 9:22 AM
    Friday, November 20, 2015 9:08 PM
  • I am logged in as the domain administrator.  I should not need credential in the script, should I?
    Friday, November 20, 2015 9:18 PM
  • I add the -DomainCredential, and get the following error:

    Rename-Computer : Computer name E033457-CAL-SSG cannot be resolved with the exception: No such host is known.
    At C:\Rename computer.ps1:2 char:30
    + Foreach ( $Computer in $a ) {Rename-Computer -NewName $Computer.NewName -Compute ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (E033457-CAL-SSG:String) [Rename-Computer], InvalidOperationException
        + FullyQualifiedErrorId : AddressResolutionException,Microsoft.PowerShell.Commands.RenameComputerCommand

    Here is the modified script:

    $a = Import-Csv ComputerNames.csv 
    Foreach ( $Computer in $a ) {Rename-Computer -NewName $Computer.NewName -ComputerName $Computer.Name -DomainCredential DomainX\DomainCredential -Force -Restart}

    The actual script has the actual domain name and actual credential.

    Friday, November 20, 2015 9:33 PM
  • Renaming and joining require credentials because the computer will be out ot the domain during the rename.  It has to use the credentials to get back into the domain.

    \_(ツ)_/

    Friday, November 20, 2015 9:45 PM
  • Start by reading the complete help for all of the rules: https://technet.microsoft.com/en-us/library/hh849792.aspx?f=255&MSPPError=-2147217396

    \_(ツ)_/

    Friday, November 20, 2015 9:47 PM
  • Credential must be an admin.

    You should not use dashes in names as they are know to produce issues.

    Try one computer with explicit strings to make sure the dashes are not the issue.    Be sure the computer is pingable by name.


    \_(ツ)_/

    Friday, November 20, 2015 9:53 PM
  • I got the script to work, but only after turning the firewall off on the target computer.  Any idea what setting is missing in my GPO that would cause the script not to work when the firewall is turned on?  Thanks.
    Friday, November 20, 2015 11:02 PM
  • Remote management exceptions.


    \_(ツ)_/

    Friday, November 20, 2015 11:47 PM
  • In the workstation GPO:
    Computer Config -> Administrative Templates -> Network Connections -> Windows Firewall -> Domain Profile: Windows Firewall Allow inbound Remote Administration Exception : Enabled

    \_(ツ)_/

    • Proposed as answer by Wendy Jiang Monday, November 23, 2015 8:23 AM
    • Marked as answer by Elaine Jing Monday, December 7, 2015 9:22 AM
    Friday, November 20, 2015 11:51 PM
  • Thanks I will try that when I get back to work next week.
    Monday, November 23, 2015 5:08 PM
  • Thanks for your help.  I was able to apply the setting from the GPO I have setup on the domain controller, and the script worked.
    Tuesday, December 1, 2015 7:03 PM
  • Just out of curiosity, what kind of problems are dashes known to cause?

    Everyone are using them all the time and I've never heard of any problems related to a dash (hyphen) in a computer name.

    Windows 7 and other operating systems even suggest computer names such as "John-PC" by default when installing non-domain joined computers.

    Tuesday, December 1, 2015 8:17 PM
  • For the script I just got to work, the computer name had dashes in it. 
    Tuesday, December 1, 2015 8:22 PM
  • Dashes should not be a problem in any object name, that I am aware of.

    Richard Mueller - MVP Directory Services

    Tuesday, December 1, 2015 8:38 PM
  • After more testing, if I run the script and there are more than one computer in the csv file to change names, I am asked for credentials for each computer that is going to be renamed.  So for example if I wanted to change the name on 10 computers, I would have to enter my credentials 10 times.  Is there a way to run this script and only enter my credentials one time.
    Wednesday, January 20, 2016 7:25 PM
  • You can create a credential object and reuse it:


    $cred = Get-Credential


    Wednesday, January 20, 2016 7:29 PM
  • I am pretty new to Powershell.  Where in the script do I do this?  Here is the script I am using:

    $a = Import-Csv ComputerNames.csv 
    Foreach ( $Computer in $a ) {Rename-Computer -NewName $Computer.NewName -ComputerName $Computer.Name -DomainCredential DomainName\DomainAdmin -Force -Restart}

    Thanks for any assistance.

    Wednesday, January 20, 2016 10:41 PM