SetupComplete - Enable Builtin Administrator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
Set-StrictMode -version Latest | |
$path = "$($Env:SystemRoot)\OEM" | |
New-Item -ItemType Directory -Path $path -Force | |
# Use single-quote for the here-string so the text isn't interpolated | |
@' | |
$adminAccount = Get-WmiObject Win32_UserAccount -filter "LocalAccount=True" | ?{$_.SID -Like "S-1-5-21-*-500"} | |
if($adminAccount.Disabled) | |
{ | |
Write-Host "Admin account was disabled. Enabling the Admin account." | |
$adminAccount.Disabled = $false | |
$adminAccount.Put() | |
} | |
else | |
{ | |
Write-Host "Admin account is enabled." | |
} | |
# Since we are using SetupComplete2.cmd, add a hook for future us to use SetupComplete3.cmd | |
if (Test-Path $Env:SystemRoot\OEM\SetupComplete3.cmd) | |
{ | |
& $Env:SystemRoot\OEM\SetupComplete3.cmd | |
} | |
'@ | Out-File -Encoding ASCII -FilePath "$path\SetupComplete2.ps1" | |
"powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File %~dp0SetupComplete2.ps1" | Out-File -Encoding ASCII -FilePath "$path\SetupComplete2.cmd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment