Coach 40
Coach 405mo ago

```# PowerShell script to change the hostname of a computer, on the variable you need to change the

# PowerShell script to change the hostname of a computer, on the variable you need to change the name of the machine that you want to change.

# Define the new hostname
$newHostName = "NewHostName"

# Use the WMI object to set the new hostname
$computerInfo = Get-WmiObject Win32_ComputerSystem
$operationResult = $computerInfo.Rename($newHostName)

# Check the result of the rename operation
if ($operationResult.ReturnValue -eq 0) {
Write-Host "Hostname changed successfully to $newHostName. Please restart the computer."
} else {
Write-Host "Failed to change hostname. Error Code: $($operationResult.ReturnValue)"
}
# PowerShell script to change the hostname of a computer, on the variable you need to change the name of the machine that you want to change.

# Define the new hostname
$newHostName = "NewHostName"

# Use the WMI object to set the new hostname
$computerInfo = Get-WmiObject Win32_ComputerSystem
$operationResult = $computerInfo.Rename($newHostName)

# Check the result of the rename operation
if ($operationResult.ReturnValue -eq 0) {
Write-Host "Hostname changed successfully to $newHostName. Please restart the computer."
} else {
Write-Host "Failed to change hostname. Error Code: $($operationResult.ReturnValue)"
}
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?