Skip to content

Instantly share code, notes, and snippets.

@janbuettiker
Last active February 20, 2023 09:30
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 janbuettiker/fb68b98f7929aef45e4dee3455314fd3 to your computer and use it in GitHub Desktop.
Save janbuettiker/fb68b98f7929aef45e4dee3455314fd3 to your computer and use it in GitHub Desktop.
SetupComplete - Enable Builtin Administrator
$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