Rename a computer in PowerShell

Rename-Computer PowerShell cmdlet renames the local computer or remote computer. In this article, I will explain how to rename a computer in PowerShell with examples.

Rename-Computer cmdlet in PowerShell has New-Name parameter specify a new name for target computer ( local or remote computer).

Let’s understand Rename-Computer cmdlet in PowerShell to rename local computer or remote computer with examples.

Rename-Computer Syntax

It renames a computer name to specified new name.

Syntax:

Rename-Computer
      [-ComputerName <String>]
      [-PassThru]
      [-DomainCredential <PSCredential>]
      [-LocalCredential <PSCredential>]
      [-NewName] <String>
      [-Force]
      [-Restart]
      [-WsmanAuthentication <String>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Parameters:

-ComputerName

Parameter rename the remote computer in PowerShell. Default is local computer. To rename a remote computer, specify IP address, domain name of remote computer or NetBIOS name. To specify local computer name, use localhost, dot (.).

-NewName

It specify new name for a computer. This parameter is mandatory to rename a computer. Name may contains alphanumeric, hyphens (-).

-Restart

It specify restart is required after computer renamed. Restart is required to reflect the changes.

-DomainCredential

It specify a user account that has permission to connect to remote computer in domain and rename a computer joined in domain with explicit credentials. Use Domain\User or use Get-Credential cmdlet to get user credentials.

-Force

Force parameter forces the command to execute without user confirmation.

Let’s understand rename-computer cmdlet in PowerShell with examples

Rename a Local Computer

To rename a local computer, use rename-computer cmdlet in PowerShell as below

Rename-Computer -NewName "IN-CORP101" -Restart

In the above PowerShell rename-computer rename a local computer name to IN-CORP101 specified by NewName parameter. It will restart local computer to reflect change after renamed.

Rename a Remote computer

To rename a remote computer, use rename-computer cmdlet in PowerShell as below

Rename-Computer -ComputerName "IN-CORP01" -NewName "IN-CORP02" -Restart

In the above PowerShell script, rename-computer cmdlet renames a remote computer name. ComputerName parameter specify remote computer name and NewName parameter specify new name for computer.

After computer renamed, remote computer will restart to reflect changes.

PowerShell Rename a Computer on Domain

To rename a computer on domain, user must have permission to connect to the domain. For explicit credentials, use Get-Credential cmdlet in PowerShell.

Let’s rename computer on domain using rename-computer cmdlet in PowerShell.

Rename-Computer -ComputerName "EU-COPR10" -NewName "EU-CORP20" -DomainCredential ShellGeek\Admin -Force

In the above PowerShell script, Rename-Computer cmdlet renames a remote computer joined on domain. ComputerName specified remote computer name, NewName parameter specify new name for computer.

DomainCredential parameter specify domain user ShellGeek\Admin who has permission to connect to domain computer and rename a computer on domain.

Conclusion

I hope above article on rename a computer in PowerShell will help you to rename a local computer or remote computer.

Rename-Computer cmdlet in PowerShell doesn’t have parameter that take input value and returns ComputerChangeInfo object if you specify -PassThru parameter else return does not return any value.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment