Fix Domain Trust Issues
This script with fix domain trust issues when run as a local admin on a machine.
Code
| <#
.SYNOPSIS
Fixed domain trust issues.
.DESCRIPTION
Run on the machine with domain trust issues as a local administrator.
If you get an error after running this, try moving the machine
AD object into the Computers OU and wait 30 minutes and try again.
.NOTES
REVISION ID : 1
UPDATED : 2024-09-23
AUTHOR : Noxcivis
LICENSE : MIT
SOURCE : https://noxcivis.supportmarks.com
NOTES : No additional notes
LOCAL ADMIN : YES
REMOTE ADMIN : No
#>
Clear-Host
# PowerShell script to resolve domain trust issues
# Ensure the script is run as an administrator
if (-not ([Security.Principal.WindowsPrincipal]
[Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Error "You need to run this as an administrator."
exit
}
# Define the domain and machine name
$defaultDomain = "Corp"
$domain = Read-Host "Please enter the domain name (default: $defaultDomain)"
if ([string]::IsNullOrWhiteSpace($domain)) {
$domain = $defaultDomain
}
$machine = $env:COMPUTERNAME
# Reset the machine account password
try {
$credential = Get-Credential -Message "Enter domain admin credentials"
Reset-ComputerMachinePassword -Server $domain -Credential $credential
Write-Output "Successfully reset the machine account password for $machine in domain $domain."
} catch {
Write-Error "Failed to reset the machine account password. Error: $_"
}
# Restart the computer to apply changes
Restart-Computer -Force
|
TIP
Save as fix-domain-trust-issues.ps1