Hi guys,
Quite long time ago I created a batch to re-create windows profile on the machine automatically when user asks for support.
Since migration to windows 10 I'm facing the following issue:
When someone from support department executes script on some w10 (1703) machines user can log in to the machine only with Temp profile.
Nonetheless, machine successfully contacts the domain and recognizes a user, however profile remains temporary.
The command sequence:
======================
@echo off
echo.
:enteruname
set /p uname=Please enter userprofile folder name:
if not defined uname goto enteruname
echo.
:rename
echo 1) Renaming of user profile
if exist C:\Users\%uname%_old ren C:\Users\%uname%_old %uname%_old_%random%
ren C:\Users\%uname% %uname%_old
if %ERRORLEVEL% EQU 0 (echo User profile renamed from %uname% to %uname%_old & goto ren_ok) else (echo Failed to rename profile folder, please restart computer now!)
echo Press ANY KEY to restart a computer and then login under administrator account!
REG ADD "HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v !RecreateProfile /t REG_SZ /d c:\temp\recreate_user_profile.bat /f
pause
shutdown -r -t 0 -f
goto rename
echo.
:ren_ok
FOR /F %%a IN ('psgetsid \\%cname% %uname% /accepteula') DO set sid=%%a
echo %uname%'s SID is %sid%
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" > c:\temp\profiles.txt
findstr "%sid%" c:\temp\profiles.txt > c:\temp\usersid.txt
echo 2) Registry keys for user %uname% found:
type c:\temp\usersid.txt
pause
for /f "tokens=*" %%a in (c:\temp\usersid.txt) do reg delete "%%a" /f
if %ERRORLEVEL% EQU 0 (echo Regitry key for user %uname% deleted.) else (echo Failed to delete registry record!)
echo.
echo 3) It's time to copy user's data from old profile to a new one
REG ADD "HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v !CopyProfile /t REG_SZ /d c:\temp\copy_profile.bat /f
echo. Now you can ask user to login, after he is logged run C:\Temp\copy_profile.bat to move contents of the old profile to a new one.
echo.
timeout 7
========================
Can someone take a look and advise?
Thx