Solved

How do you create a script that will delete roaming profiles for a specific user on multiple servers?

Posted on 2008-10-21
3
1,167 Views
Last Modified: 2010-03-27
We have a Citrix server farm with roaming profiles and is looking for a script to preform deleting a specified username (directories) on several servers. Who ever can awnser this is genious.

Example:
Delete \\server1\M$\documents and settings\username
Delete \\server1\M$\documents and settings\username.001
Delete \\server1\M$\documents and settings\username.002
Delete \\server1\M$\documents and settings\username.003
Delete \\server2\M$\documents and settings\username
Delete \\server3\M$\documents and settings\username
Delete \\server3\M$\documents and settings\username.001
Delete \\server1\M$\documents and settings\username.002

The chalenge with this script is several servers have more than one profile on each server relating to username (username.001, username.002, etc)

The attached script is what we have but it only deletes
\\server1\M$\documents and settings\username
and not
\\server1\M$\documents and settings\username*
with the wildcard.

Thanks guys!

@echo off

::Citrix Profile Deletion Script

::Delete a users profile from a citrix server

::Relies on remprof.exe and servers.txt being in the installation folder

::servers.txt must have one servername per line and script must be as an administrative account.  

@echo Kicking off script:

@echo.

::checking for servers list

ECHO Checking for servers list: &  IF EXIST servers.txt (@echo Success & goto RemCheck) ELSE (@Echo Failure & goto txt-missing)
 

:RemCheck

::Checking for remprof.exe file

@echo.

ECHO Checking for Remprof.exe: &  IF EXIST remprof.exe (@echo Success & goto psexeccheck) ELSE (@Echo Failure & goto rem-missing)
 

:psexeccheck

::Checking for psexec.exe file

@echo.

ECHO Checking for psexec.exe: &  IF EXIST psexec.exe (@echo Success & goto set) ELSE (@Echo Failure & goto psexec-missing)
 
 

:set

::Setting username

@echo.

@echo Please type the network username of the HOP Citrix profile you wish to delete: & set /p user=

@echo.

@echo Deleting profile for %userdomain%\%user% from the specified servers.

goto install

exit
 

:install

psexec -accepteula @servers.txt -c remprof.exe %user% >> c:\dis\ProfileDelete\profile-deletion-log.txt

@echo Command Completed, check above for results.

pause

exit
 

:rem-missing

@echo Error! Remprof.exe is missing from installation folder

@echo.

@echo. Check the script folder of this batch file for remprof.exe, if its not there, put it there, if it is there... panic.

pause

exit
 

:txt-missing

@echo servers.txt missing from installation folder

@echo.

@echo. Check the script folder of this batch file for servers.txt, if its not there, put it there, if it is there... panic.

pause

exit
 

:psexec-missing

@echo psexec.exe missing from installation folder

@echo.

@echo. Check the script folder of this batch file for psexec.exe, if its not there, put it there, if it is there... panic.

pause

exit

Open in new window

0
Comment
Question by:dishelp
3 Comments
 
LVL 21

Accepted Solution

by:
AmazingTech earned 500 total points
ID: 22774560
Give this a try.

Currently will put the line of the command it will run into your log file c:\dis\ProfileDelete\profile-deletion-log.txt

Remove the ECHO from this line when you want it to delete the profile.
ECHO psexec -accepteula \\%%a -c remprof.exe %%b >> c:\dis\ProfileDelete\profile-deletion-log.txt

@echo off

::Citrix Profile Deletion Script

::Delete a users profile from a citrix server

::Relies on remprof.exe and servers.txt being in the installation folder

::servers.txt must have one servername per line and script must be as an administrative account.  

@echo Kicking off script:

@echo.

::checking for servers list

ECHO Checking for servers list: &  IF EXIST servers.txt (@echo Success & goto RemCheck) ELSE (@Echo Failure & goto txt-missing)

 

:RemCheck

::Checking for remprof.exe file

@echo.

ECHO Checking for Remprof.exe: &  IF EXIST remprof.exe (@echo Success & goto psexeccheck) ELSE (@Echo Failure & goto rem-missing)

 

:psexeccheck

::Checking for psexec.exe file

@echo.

ECHO Checking for psexec.exe: &  IF EXIST psexec.exe (@echo Success & goto set) ELSE (@Echo Failure & goto psexec-missing)

 

 

:set

::Setting username

@echo.

@echo Please type the network username of the HOP Citrix profile you wish to delete: & set /p user=

@echo.

@echo Deleting profile for %userdomain%\%user% from the specified servers.

goto install

exit

 

:install

FOR /f %%a in (server.txt) DO (

    FOR /f "tokens=2 delims=\" %%b in ('psexec -accepteula \\%%a -c remprof.exe ^| FIND /i "user:" ^| FIND /i "%user%"') do (

         ECHO psexec -accepteula \\%%a -c remprof.exe %%b >> c:\dis\ProfileDelete\profile-deletion-log.txt

    ) 

)

@echo Command Completed, check above for results.

pause

exit

 

:rem-missing

@echo Error! Remprof.exe is missing from installation folder

@echo.

@echo. Check the script folder of this batch file for remprof.exe, if its not there, put it there, if it is there... panic.

pause

exit

 

:txt-missing

@echo servers.txt missing from installation folder

@echo.

@echo. Check the script folder of this batch file for servers.txt, if its not there, put it there, if it is there... panic.

pause

exit

 

:psexec-missing

@echo psexec.exe missing from installation folder

@echo.

@echo. Check the script folder of this batch file for psexec.exe, if its not there, put it there, if it is there... panic.

pause

exit

Open in new window

0
 
LVL 3

Expert Comment

by:cclassen
ID: 24503561
If you are only concerned with the file structure and not registry or related profile information, how about

for %%i in (server1, server2, server3) do for %%j in ('"dir /b "\\%%i\c$\documents and settings\username.*""') do rd /s /q "\\%%i\c%\documents and settings\%%j"

If you want to test this from a command prompt, change all the %% to %.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

#SSL #TLS #Citrix #HTTPS #PKI #Compliance #Certificate #Encryption #StoreFront #Web Interface #Citrix XenApp
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now