Skip to content

Instantly share code, notes, and snippets.

@AdilHindistan
Last active May 6, 2019 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdilHindistan/7722d81f908fbd19b371 to your computer and use it in GitHub Desktop.
Save AdilHindistan/7722d81f908fbd19b371 to your computer and use it in GitHub Desktop.
##AH - Adil Hindistan - Changing name of a domain joined computer
Current Name..: Adil-Laptop1
New Name......: Adil-Laptop2
1) Registry is updated:
HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG_SZ /d Adil-Laptop2
HKLM\System\CurrentControlSet\Services\Tcpip\Parameters /v "NV Hostname" /t REG_SZ /d Adil-Laptop2
## Fun fact, simply change the above two keys and reboot, you will get error:
"the security database on the server does not have a computer account for this workstation trust relationship"
Restoring the names will fix it.
2) DnsHostName and SPN are updated in AD.
Here are relevant notes from the log at %windir%\debug\NetSetup.log:
NetpChangeMachineName: from 'ADIL-LAPTOP1' to 'adil-laptop2' using '(NULL)' [0x2]
NetpDsGetDcName: trying to find DC in domain 'XYZ', flags: 0x1010
NetpDsGetDcName: found DC '\\ADServerVM005' in the specified domain
NetpChangeMachineName: status of connecting to dc '\\ADServerVM005': 0x0
NetpGetLsaPrimaryDomain: status: 0x0
NetpManageMachineAccountWithSid: status of NetUserSetInfo on '\\ADServerVM005' for 'ADIL-LAPTOP1$': 0x0
NetpGetLsaPrimaryDomain: status: 0x0
NetpGetDnsHostName: PrimaryDnsSuffix defaulted to DNS domain name: xyz.org
NetpGetComputerObjectDn: Cracking account name XYZ\ADIL-LAPTOP2$ on \\ADServerVM005
NetpGetComputerObjectDn: Crack results: (Account already exists) DN = CN=ADIL-LAPTOP2,OU=Laptops,DC=XYZ,DC=org
NetpModifyComputerObjectInDs: Initial attribute values:
DnsHostName = adil-laptop2.xyz.org
ServicePrincipalName = HOST/adil-laptop2.xyz.org RestrictedKrbHost/adil-laptop2.xyz.org HOST/ADIL-LAPTOP2 RestrictedKrbHost/ADIL-LAPTOP2
NetpModifyComputerObjectInDs: Computer Object already exists in OU:
DnsHostName = adil-laptop1.xyz.org
ServicePrincipalName = WSMAN/ADIL-LAPTOP2 TERMSRV/ADIL-LAPTOP2 RestrictedKrbHost/ADIL-LAPTOP2 HOST/ADIL-LAPTOP2 WSMAN/adil-laptop1.xyz.org TERMSRV/adil-laptop1.xyz.org RestrictedKrbHost/adil-laptop1.xyz.org HOST/adil-laptop1.xyz.org
NetpModifyComputerObjectInDs: Attribute values to set:
DnsHostName = adil-laptop2.xyz.org
ServicePrincipalName = HOST/adil-laptop2.xyz.org RestrictedKrbHost/adil-laptop2.xyz.org
ldap_unbind status: 0x0
NetpChangeMachineName: status of setting DnsHostName and SPN: 0x0
---
* Win32_ComputerSystem has 'rename' method but it is not exposed when connected to WMI remotely. Ie. It's a local-only method.
* Cim_ComputerSystem does not have rename method
netjoin.dll -> NetpDecodeProvisioninBob
netjoin.dll -> NetpMachineValidToJoin
netjoin.dll -> NetpChangeMachineName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment