Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Citrix Profiles +require deletion

Posted on 2007-08-07
12
Medium Priority
?
448 Views
Last Modified: 2010-03-18
I have 15 Citrix servers, and sometimes a users profiles becomes corrupt, but before telling us he has ended up logging onto multiple servers, Im looking for a script that prompts for a Username and then searches the Docs and settings folders on multiple servers and deletes the profile, if the user is logged off. any help is greatly appreciated.
0
Comment
Question by:ronanfitz
  • 7
  • 3
  • 2
12 Comments
 
LVL 31

Expert Comment

by:merowinger
ID: 19644925
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 19645085
This script will do the trick:


' Script to search 15 servers and delete profile

dim filesys, demofolder, username, ArgObj

Set ArgObj = WScript.Arguments

if ArgObj.Count = 0 Then
      WScript.Echo "Ensure you specify the username or folder name of profile is first parameter!"
      WScript.Quit
End If

username = ArgObj(0)

If username = "Administrator" OR username = "Default User" OR username = "All Users" Then
      WScript.Echo "You can't delete the " & username & " profile with this script!"
      WScript.Quit
End If


set filesys = WScript.CreateObject ("Scripting.FileSystemObject")

Dim citrixservers
citrixservers = array( _
"\\server1\C$\Documents and Settings\", _
"\\server2\C$\Documents and Settings\", _
"\\server3\C$\Documents and Settings\", _
"\\server4\C$\Documents and Settings\", _
"\\server5\C$\Documents and Settings\", _
"\\server6\C$\Documents and Settings\", _
"\\server7\C$\Documents and Settings\", _
"\\server8\C$\Documents and Settings\", _
"\\server9\C$\Documents and Settings\", _
"\\server10\C$\Documents and Settings\", _
"\\server11\C$\Documents and Settings\", _
"\\server12\C$\Documents and Settings\", _
"\\server13\C$\Documents and Settings\", _
"\\server14\C$\Documents and Settings\", _
"\\server15\C$\Documents and Settings\" _
)

For each x in citrixservers
      Dim folder
      set folder = filesys.GetFolder(x & username)
      folder.Delete
Next


Copy to Notepad, File>Save As something like "profiledeleter.vbs" (ensure it's got the VBS extension)
You need to go through the array and specify the name of each of your 15 servers in place of server1 server 2 server3 etc. Make sure though that you keep the \\ before the name and \C$\Documents and Settings\ afterwards.
I've used C$ to get to the C drive (the default admin share) but if for some reason that's turned off or you have another share to get there do that instead.

To run the script, from a command prompt switch to the folder it's running in and type

"profiledeleter.vbs" username

So for a profile with folder name joebloggs you would type
"profiledeleter.vbs" joebloggs

I've put built in detection for any malicious attempt to delete the Administrator, Default User or All Users profiles so it won't allow any of those to be deleted.

If the profile folder name has a space in it you would need to type
"profiledeleter.vbs" "joe bloggs"
(put the folder name in quotes)

Hope this is what you wanted

tigermatt
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 19645238
In actual fact my above script has a slight problem. It should in fact be as below.


' Script to search 15 servers and delete profile

dim filesys, username, ArgObj

Set ArgObj = WScript.Arguments

if ArgObj.Count = 0 Then
      WScript.Echo "Ensure you specify the username or folder name of profile is first parameter!"
      WScript.Quit
End If

username = ArgObj(0)

If username = "Administrator" OR username = "Default User" OR username = "All Users" Then
      WScript.Echo "You can't delete the " & username & " profile with this script!"
      WScript.Quit
End If


set filesys = WScript.CreateObject ("Scripting.FileSystemObject")

Dim citrixservers
citrixservers = array( _
"\\server1\C$\Documents and Settings\", _
"\\server2\C$\Documents and Settings\", _
"\\server3\C$\Documents and Settings\", _
"\\server4\C$\Documents and Settings\", _
"\\server5\C$\Documents and Settings\", _
"\\server6\C$\Documents and Settings\", _
"\\server7\C$\Documents and Settings\", _
"\\server8\C$\Documents and Settings\", _
"\\server9\C$\Documents and Settings\", _
"\\server10\C$\Documents and Settings\", _
"\\server11\C$\Documents and Settings\", _
"\\server12\C$\Documents and Settings\", _
"\\server13\C$\Documents and Settings\", _
"\\server14\C$\Documents and Settings\", _
"\\server15\C$\Documents and Settings\" _
)

For each x in citrixservers
      Dim folder
      folder = x & username
      
      If filesys.FolderExists(folder) Then
            Dim directorytodelete
            Set directorytodelete = filesys.GetFolder(folder)
            directorytodelete.Delete
      End If
Next


I made the mistake of forgetting to check whether the profile actually existed on the remote server since the user may not have logged in to all 15 servers. Now it will just gracefully continue should the profile not exist on one of the servers, and will delete it if it does exist.

Usage and parameters remain the same.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 58

Accepted Solution

by:
tigermatt earned 500 total points
ID: 19645301
Alternatively, if you want a better way of typing it in (instead of using command prompt) then this script will popup a message box requesting for you to type in the username. Just a better GUI that's all.


' Script to search 15 servers and delete profile

dim filesys, username, ArgObj

' Prompt user for input
Dim message, title, default
message = "Please enter the username or name of directory to be deleted from 15 servers' C:\Documents and Settings"
title = "Enter username"
default = ""
username = InputBox(message,title,default)

' Check we got something
If username = "" Then
      WScript.Echo "You must enter a username when prompted!"
      WScript.Quit
End If

If username = "Administrator" OR username = "Default User" OR username = "All Users" Then
      WScript.Echo "You can't delete the " & username & " profile with this script!"
      WScript.Quit
End If


set filesys = WScript.CreateObject ("Scripting.FileSystemObject")

Dim citrixservers
citrixservers = array( _
"\\server1\C$\Documents and Settings\", _
"\\server2\C$\Documents and Settings\", _
"\\server3\C$\Documents and Settings\", _
"\\server4\C$\Documents and Settings\", _
"\\server5\C$\Documents and Settings\", _
"\\server6\C$\Documents and Settings\", _
"\\server7\C$\Documents and Settings\", _
"\\server8\C$\Documents and Settings\", _
"\\server9\C$\Documents and Settings\", _
"\\server10\C$\Documents and Settings\", _
"\\server11\C$\Documents and Settings\", _
"\\server12\C$\Documents and Settings\", _
"\\server13\C$\Documents and Settings\", _
"\\server14\C$\Documents and Settings\", _
"\\server15\C$\Documents and Settings\" _
)

For each x in citrixservers
      Dim folder
      folder = x & username
      
      If filesys.FolderExists(folder) Then
            Dim directorytodelete
            Set directorytodelete = filesys.GetFolder(folder)
            directorytodelete.Delete
      End If
Next


It doesn't however require that usernames with spaces in be typed in with quotes.
Remember to set the servers in the array from server1 through to server15

tigermatt
0
 
LVL 31

Expert Comment

by:merowinger
ID: 19645338
Alternative u can install the User Profile Hive Cleanup Service from Microsoft on your TS
It prevents possible problems in advance
0
 
LVL 31

Expert Comment

by:merowinger
ID: 19645341
0
 

Author Comment

by:ronanfitz
ID: 19646495
Tigermatt,

Great script, helped alot, cuts down on the donkey work when theres problems.

Thanks again
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 19646664
Brilliant - I'm glad I managed to knock something up which worked, long time since I last did VBS scripting but google's always there to help!

If you ever get any more servers then you can easily add them to the list, just follow the pattern from one of the entries in the middle of the array. (Leave the end one as is)
0
 

Author Comment

by:ronanfitz
ID: 19647480
works very well, The only problem I get is if a profile is locked open by a uer it wont delete, is there any way that it can report which server it errored on?
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 19648249
I'll see what I can do and post back
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 19648254
I'm assuming you're using the one with the input box and GUI (third one), so I'll investigate it on that script?
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 19648652
Hi there

I've updated the script as below
After you enter the username to the prompt as before, it will go off and do the delete without erroring if a profile is locked for some reason.

However once it has gone through all 15 servers it will give an on-screen prompt to tell you what happened on each server.

So an example prompt might be:

Deleting profile for joebloggs...
\\server1\C$\Documents and Settings\joebloggs - Profile not present
\\server2\C$\Documents and Settings\joebloggs - Unable to delete profile
\\server3\C$\Documents and Settings\joebloggs - Deleted profile from server successfully

The first one as it sounds means that the folder specified does not exist on the server
The second is telling you the profile was locked or a file within locked for some reason
The third does as it says, it was deleted successfully

Any more issues let me know.


' Script to search servers and delete profile for specified user

dim filesys, username, ArgObj

' Prompt user for input
Dim prompt, title, default
prompt = "Please enter the username or name of directory to be deleted from 15 servers' C:\Documents and Settings"
title = "Enter username"
default = ""
username = InputBox(prompt,title,default)

' Check we got something
If username = "" Then
      WScript.Echo "You must enter a username when prompted!"
      WScript.Quit
End If

If username = "Administrator" OR username = "Default User" OR username = "All Users" Then
      WScript.Echo "You can't delete the " & username & " profile with this script!"
      WScript.Quit
End If


set filesys = WScript.CreateObject ("Scripting.FileSystemObject")

Dim citrixservers
citrixservers = array( _
"\\server1\C$\Documents and Settings\", _
"\\server2\C$\Documents and Settings\", _
"\\server3\C$\Documents and Settings\", _
"\\server4\C$\Documents and Settings\", _
"\\server5\C$\Documents and Settings\", _
"\\server6\C$\Documents and Settings\", _
"\\server7\C$\Documents and Settings\", _
"\\server8\C$\Documents and Settings\", _
"\\server9\C$\Documents and Settings\", _
"\\server10\C$\Documents and Settings\", _
"\\server11\C$\Documents and Settings\", _
"\\server12\C$\Documents and Settings\", _
"\\server13\C$\Documents and Settings\", _
"\\server14\C$\Documents and Settings\", _
"\\server15\C$\Documents and Settings\" _
)

Dim message
message = "Deleting profile for " & username & "..." & vbCrLf

For each x in citrixservers
      Dim folder, profileexists
      folder = x & username
      
      If filesys.FolderExists(folder) Then
            on error resume next
            Dim directorytodelete
            Set directorytodelete = filesys.GetFolder(folder)
            directorytodelete.Delete
            on error goto 0
            profileexists = 1
      Else
            profileexists = 0
      End If
      
      ' Check if it existed to start with
      If profileexists = 0 Then
            message = message & folder & " - Profile not present" & vbCrLf
      Else
            ' Profile exists
            ' Has it been deleted?
            If filesys.FolderExists(folder) Then
                  message = message & folder & " - Unable to delete profile" & vbCrLf
            Else
                  message = message & folder & " - Deleted profile from server successfully" & vbCrLf
            End If
      End If
Next

' Echo status
WScript.Echo message
WScript.Quit
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Citrix policies are the most efficient method to configure and tune XenDesktop environments, allowing organizations to control connection, security and bandwidth settings based on various combinations of users, devices or connection types.  Citrix …
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

571 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