Skip to content

Instantly share code, notes, and snippets.

@rupertbg
Created July 4, 2024 10:38
Show Gist options
  • Save rupertbg/f56cd249bcb45028ccca08c190d926f3 to your computer and use it in GitHub Desktop.
Save rupertbg/f56cd249bcb45028ccca08c190d926f3 to your computer and use it in GitHub Desktop.
POV: You've deleted an active directory computer account and you don't have recycle bin turned on
# Create a new matching computer account in the Active Directory then..
# Reset the computer machine password as a domain account
$DomainName = "example.com"
$DomainUser = "adomainadminaccount@example.com"
$DomainPassword = "yoursupergreatpassword"
$DomainController = "dc1.example.com"
$SecurePassword = ConvertTo-SecureString -String $DomainPassword -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($DomainUser, $SecurePassword)
Reset-ComputerMachinePassword -Server $DomainController -Credential $Credential
# Repair the computer secure channel using a local account
$User = "Administrator"
$Password = "thereallystrongadministratorpassword"
$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($User, $SecurePassword)
Test-ComputerSecureChannel -Repair -Credential $Credential
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment