Rename Profile Batch Script – Citrix / Terminal Server






Some time ago, after finding myself manually removing/renaming user profiles from several servers as well as a roaming profile share, I wrote the below batch script to enable me to perform the rename profile function quickly & easily.

The server names are all defined early on, the only input required is typing the domain username & confirming entry is correct, before the profiles are renamed.

The script will rename each found profile, and rename it to %username%.OLD.%date% in order to protect any data contained within.

@echo off
setLocal EnableDelayedExpansion

:menu1    
echo [Enter Username To Delete Profile From Citrix:]

echo.    
set /p pr=    
echo.    


:menu2
setLocal EnableDelayedExpansion
echo [Username to remove: %pr%. Is this correct?]
echo 1 for Yes   
echo 2 for No  
echo.    
set /p rr=    
echo.   
if %rr% neq 1 goto :menu1


:begin 
SET SERVER1=CITRIX1
SET SERVER2=CITRIX2
SET SERVER3=CITRIX3
SET SERVER4=CITRIX4
SET SERVER5=\\server\citrixroaming


:server1
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c 
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b 
if exist "\\%SERVER1%\C$\Documents and Settings\" goto exist1 
echo PATH NOT FOUND on %SERVER1%, PROGRESSING....
goto Server2

:exist1 
echo PATH CONFIRMED 
pushd \\%SERVER1%\C$\Documents and Settings\ 
goto skipit1 

:skipit1
if exist "\\%SERVER1%\C$\Documents and Settings\%pr%" goto found1
echo ID NOT FOUND ON %SERVER1%....
goto server2

:found1
Echo modifying... 
rename "%pr%" "%pr%"."%XDate%" 
Echo ***SUCCESS*** 
popd 
Echo Renamed to %pr%.%XDate%ON %SERVER1%....
goto server2


:server2
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c 
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b 
if exist "\\%SERVER2%\C$\Documents and Settings\" goto exist2
echo PATH NOT FOUND on %SERVER2%, PROGRESSING....
goto Server3

:exist2
echo PATH CONFIRMED 
pushd \\%SERVER2%\C$\Documents and Settings\ 
goto skipit2

:skipit2
if exist "\\%SERVER2%\C$\Documents and Settings\%pr%" goto found2
echo ID NOT FOUND ON %SERVER2%....
goto server3

:found2
Echo modifying... 
rename "%pr%" "%pr%"."%XDate%" 
Echo ***SUCCESS*** 
popd 
Echo Renamed to %pr%.%XDate%ON %SERVER2%....
goto server3


:server3
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c 
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b 
if exist "\\%SERVER3%\C$\Documents and Settings\" goto exist3
echo PATH NOT FOUND on %SERVER3%, PROGRESSING....
goto Server4

:exist3
echo PATH CONFIRMED 
pushd \\%SERVER3%\C$\Documents and Settings\ 
goto skipit3

:skipit3
if exist "\\%SERVER3%\C$\Documents and Settings\%pr%" goto found3
echo ID NOT FOUND ON %SERVER3%....
goto server4

:found3
Echo modifying... 
rename "%pr%" "%pr%"."%XDate%" 
Echo ***SUCCESS*** 
popd 
Echo Renamed to %pr%.%XDate%ON %SERVER3%....
goto server4


:server4
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c 
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b 
if exist "\\%SERVER4%\C$\Documents and Settings\" goto exist4
echo PATH NOT FOUND on %SERVER4%, PROGRESSING....
goto Server5

:exist4
echo PATH CONFIRMED 
pushd \\%SERVER4%\C$\Documents and Settings\ 
goto skipit4

:skipit4
if exist "\\%SERVER4%\C$\Documents and Settings\%pr%" goto found4
echo ID NOT FOUND ON %SERVER4%....
goto server5

:found4
Echo modifying... 
rename "%pr%" "%pr%"."%XDate%" 
Echo ***SUCCESS*** 
popd 
Echo Renamed to %pr%.%XDate%ON %SERVER4%....
goto server5


:server5
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c 
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b 
if exist "%SERVER5%" goto exist5
echo PATH NOT FOUND on %SERVER5%..
goto final

:exist5
echo PATH CONFIRMED 
pushd %SERVER5%\ 
goto skipit5

:skipit5
if exist "%SERVER5%\%pr%.domain" goto found5
echo ID NOT FOUND ON %SERVER5%...
goto final

:found5
Echo modifying... 
rename "%pr%.domain" "%pr%"OLD.OLD."%XDate%" 
Echo ***SUCCESS*** 
popd 
Echo Renamed to %pr%.domain.%XDate%ON %SERVER5%....

goto final

:final
Echo COMPLETED!!
Pause

 





This entry was posted in Batch, Profile, Script. Bookmark the permalink.

Leave a Reply