Initial commit
This commit is contained in:
51
scripts/powershell/rename-hide-accounts.ps1
Normal file
51
scripts/powershell/rename-hide-accounts.ps1
Normal file
@@ -0,0 +1,51 @@
|
||||
[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# --- 1. Rename local account 'user' -> 'User' ---
|
||||
$src = 'user'
|
||||
$dst = 'User'
|
||||
|
||||
$u = Get-LocalUser -Name $src -ErrorAction SilentlyContinue
|
||||
if ($u) {
|
||||
if ($u.Name -ceq $dst) {
|
||||
Write-Host "[=] Account is already '$dst'"
|
||||
} else {
|
||||
Write-Host "[*] Renaming local account '$($u.Name)' -> '$dst'"
|
||||
Rename-LocalUser -Name $src -NewName $dst
|
||||
Write-Host "[OK] Renamed"
|
||||
}
|
||||
} else {
|
||||
$already = Get-LocalUser -Name $dst -ErrorAction SilentlyContinue
|
||||
if ($already) {
|
||||
Write-Host "[=] Account '$dst' already exists (no '$src' found). Nothing to rename."
|
||||
} else {
|
||||
throw "Neither '$src' nor '$dst' exists as local user"
|
||||
}
|
||||
}
|
||||
|
||||
# --- 2. Hide 'Admin' from sign-in screen ---
|
||||
$listPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList'
|
||||
if (-not (Test-Path $listPath)) {
|
||||
New-Item -Path $listPath -Force | Out-Null
|
||||
Write-Host "[*] Created $listPath"
|
||||
}
|
||||
New-ItemProperty -Path $listPath -Name 'Admin' -Value 0 -PropertyType DWord -Force | Out-Null
|
||||
Write-Host "[OK] Hidden 'Admin' from sign-in screen (SpecialAccounts\UserList\Admin = 0)"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=== Post-state ==="
|
||||
Get-LocalUser | Select-Object Name,Enabled,LastLogon | Format-Table -AutoSize
|
||||
|
||||
$lst = Get-ItemProperty -Path $listPath -ErrorAction SilentlyContinue
|
||||
if ($lst) {
|
||||
Write-Host "UserList values:"
|
||||
$lst.PSObject.Properties | Where-Object { $_.Name -notmatch '^PS' } | ForEach-Object {
|
||||
Write-Host (" {0} = {1}" -f $_.Name, $_.Value)
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Notes:"
|
||||
Write-Host " - Account SIDs don't change. C:\Users\user profile folder stays with lowercase name"
|
||||
Write-Host " (NTFS is case-insensitive so all apps keep working)."
|
||||
Write-Host " - Admin can still sign in: click 'Other user' on the lock screen and type 'Admin'."
|
||||
Reference in New Issue
Block a user