Created
February 17, 2026 05:31
-
-
Save azunyuuuuuuu/7f3f8a1ea0f3c1a6e4580683291bcaec to your computer and use it in GitHub Desktop.
The script available in Windows 11 which can be used during the OOBE step to set the user folder name in c:\users\<usernam> to whatever you want
This file contains hidden or 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
| @echo off | |
| setlocal enabledelayedexpansion | |
| chcp 65001 >nul | |
| set "input=%*" | |
| if "%input%"=="" ( | |
| echo Usage: SetDefaultUserFolder.cmd ^<value^> | |
| echo Example: SetDefaultUserFolder.cmd MyFolderName | |
| exit /b 1 | |
| ) | |
| :: Now call PowerShell for detailed Unicode and reserved name validation | |
| powershell -NoProfile -Command ^ | |
| "$name = '%input%'.Trim();" ^ | |
| "$invalid = [System.IO.Path]::GetInvalidFileNameChars() + @('@', '.', ';', '=', ',', '+');" ^ | |
| "if ([string]::IsNullOrWhiteSpace($name)) { Write-Host '[ERROR] Name is empty or whitespace.'; exit 1 }" ^ | |
| "elseif ($name.Length -gt 16) { Write-Host '[ERROR] Name exceeds 16 character limit.'; exit 2 }" ^ | |
| "elseif ($name.EndsWith(' ') -or $name.EndsWith('.')) { Write-Host '[ERROR] Name cannot end with space or dot.'; exit 1 }" ^ | |
| "elseif ('CON','PRN','AUX','NUL','COM1','COM2','COM3','COM4','COM5','COM6','COM7','COM8','COM9','LPT1','LPT2','LPT3','LPT4','LPT5','LPT6','LPT7','LPT8','LPT9' -contains $name.ToUpper()) { Write-Host \"[ERROR] '$name' is a reserved name.\"; exit 1 }" ^ | |
| "elseif ($invalidChar = $name.ToCharArray() | Where-Object { $invalid -contains $_ } | Select-Object -First 1) { Write-Host \"[ERROR] Invalid character found in name: '$invalidChar'\"; exit 1 }" ^ | |
| "else { Write-Host \"[OK] '$name' is a valid folder name.\" }" | |
| if errorlevel 1 ( | |
| echo [ERROR] Folder name validation failed in PowerShell. | |
| exit /b 4 | |
| ) | |
| :: Write to registry | |
| reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\UserOOBE /v SetSAMFolderName /t REG_SZ /d "%input%" /f >nul | |
| if %errorlevel% EQU 0 ( | |
| echo [SUCCESS] Default user folder set to: %input% | |
| ) else ( | |
| echo [ERROR] Failed to set registry value. %errorlevel% | |
| exit /b 5 | |
| ) | |
| exit /b 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment