Rename-Computer cmdlet in PowerShell renames the local computer or remote computer name. It has a New-Name parameter to specify a new name for the local or remote computer.
In this article, we will discuss how to rename a computer in PowerShell using the Rename-Computer
cmdlet and how to change a local computer name or remote computer name with examples.
PowerShell Rename-Computer Syntax
Rename-Computer cmdlet renames a computer name to a specified new name using the following syntax.
Syntax:
Rename-Computer [-ComputerName <String>] [-PassThru] [-DomainCredential <PSCredential>] [-LocalCredential <PSCredential>] [-NewName] <String> [-Force] [-Restart] [-WsmanAuthentication <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Parameters:
-ComputerName
Parameter renames the remote computer in PowerShell. The default is the local computer.
To rename a remote pc, specify the IP address, the domain name of the remote computer, or the NetBIOS name.
To specify the local computer name, use localhost, dot (.).
-NewName
It specifies a new name for a computer. This parameter is mandatory to change a computer name. The name may contain alphanumeric, hyphens (-).
-Restart
It specifies restart is required after the computer is renamed. Restart is required to reflect the changes.
-DomainCredential
It specifies a user account with permission to connect to a remote computer in the domain and renames a computer joined in the domain with explicit credentials.
Use Domain\User or use the Get-Credential cmdlet to get user credentials.
-Force
The Force parameter forces the command to execute without user confirmation.
Let’s understand rename-computer
cmdlet in PowerShell with examples.
PowerShell Rename-Computer to Change Local Computer Name
To change a local computer name, use the rename-computer cmdlet in PowerShell as below
Rename-Computer -NewName "IN-CORP101" -Restart
In the above PowerShell script, the rename-computer uses the NewName parameter to set a local computer name to IN-CORP101. After script execution, it will restart the local computer to reflect the change after the computer rename.
Rename a Remote computer using PowerShell
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 to rename the computer, the rename-computer
cmdlet uses ComputerName
parameter to specify a remote computer name and the NewName
parameter to specify a new name for the computer.
After the script execution to rename the PC, the remote computer will restart to reflect the changes.
Rename Domain Computer using PowerShell
To rename a computer on the domain, the user must have permission to connect to the domain. For explicit credentials, use Get-Credential
cmdlet in PowerShell.
Let’s set the remote server name on the domain using the 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 a domain.
ComputerName specifies the remote computer name, NewName parameter specifies a new name for the computer.
DomainCredential
parameter specify domain user ShellGeek\Admin who has permission to connect to the domain computer and rename a computer on the domain.
Conclusion
I hope the above article to rename a computer in PowerShell will help you change a local or remote computer host name.
The PowerShell Rename-Computer cmdlet uses the NewName
parameter to change the computer name or host name of a local or remote computer.
The Rename-Computer
cmdlet in PowerShell doesn’t have a parameter that takes the input value and returns ComputerChangeInfo an object if you specify -PassThru a parameter else return does not return any value.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.