Rename Computer - PowerShell


Overview

Rename-Computer is a PowerShell command used to modify the name of a computer in an Active Directory domain or workgroup. It enables administrators to change the hostname and NetBIOS name of a computer.

Syntax

Rename-Computer [-NewName] <String> [-DomainCredential] <PSCredential> [-Force] [-PassThru] [-Confirm] [-WhatIf] [-IncludeADChanges] [-UpdateDNS]

Options/Flags

| Option | Description |
|—|—|
| -NewName | Specifies the new name for the computer. |
| -DomainCredential | PSCredential object representing the credentials of a user with permission to rename the computer in the domain. |
| -Force | Overwrites any existing computer with the same name. |
| -PassThru | Returns a PSObject representing the renamed computer. |
| -Confirm | Prompts for confirmation before executing the command. |
| -WhatIf | Simulates the operation without making any changes. |
| -IncludeADChanges | Updates Active Directory settings. |
| -UpdateDNS | Updates DNS records accordingly. |

Examples

Simple rename:

Rename-Computer -NewName "New-Computer-Name"

Rename with domain credentials:

$credential = Get-Credential
Rename-Computer -NewName "New-Computer-Name" -DomainCredential $credential

Rename with Force and UpdateDNS:

Rename-Computer -NewName "New-Computer-Name" -Force -UpdateDNS

Common Issues

  • “Access denied” error: Ensure that the user has sufficient permissions to rename the computer.
  • “Computer not found” error: Verify that the specified computer name is correct and exists in the domain or workgroup.
  • DNS updates fail: Make sure the DNS server is accessible and has the necessary permissions to update the records.

Integration

Combining with New-DNSPtrRecord

Rename-Computer -NewName "New-Computer-Name" -UpdateDNS
New-DNSPtrRecord -Name "New-Computer-Name" -Destination "New-Computer-IP"
  • Get-ComputerName: Gets the current computer name.
  • Join-Domain: Adds a computer to a domain.
  • Set-ComputerName