The Shonk Project
Home
Tuesday, 29 July 2014
Main Menu
Home
News
Blogs
Scripts
Contact Us


Syndicate
Delete Profiles Script v1.9 PDF Print
Written by Joe Shonk   
Friday, 29 August 2008

Hello,  I am happy to announce that v1.9 of the Delete Profiles script is ready for release.   Two new features have been added since v1.8.

New Features:

Inclusion\Exclusion List with wildcard support
Delete Profiles based off of Profile age

The inclusion list specifies which profile or profiles you want to delete.  A specific profile can be specified or a wildcard can be used.  Multiple profiles can be specified by placing a , (comma) or | (pipe) between each entry.
For example:

  cscript.exe DeleteProfiles.vbs /I bob,*_admin,xx*,*q*

This example will delete the profile for Bob, any profile that ends with _admin, any profile starts with xx and to top it off we are going to delete any profile that has the letter q in it.  All other profiles will remain.

We can change this to an exclusion list by replacing the /I switch with /E.
For example:

  cscript.exe DeleteProfiles.vbs /E bob,*_admin,xx*,*q*

Now we have told the script to do the exact opposite.  It will delete all profiles except for Bob, those ending in _admin, those starting with xx and any with the letter q in the name.

Note that the Inclusion and Exclusion switches are mutually exclusive.  You cannot specify both at the same time.  Also, profile names are not case sensitive.  If you specify /E BOB the script will treat the item the same as if you specified /E bob.

The days retention switch is fairly simple.  If you only want to delete profiles older than a specified number of days then use the /D xx where xx will be in number of days.  The days rentention switch can also be use in combination with the Inclusion and Exclusion list.
For example:

  cscript.exe DeleteProfiles.vbs /I bob,joe /D 10

Only Bob's and Joe's profile will be delete provided they are older than 10 days.  If we change this to an Exclusion list then all profiles older that 10 days will be deleted with the exception of Bob and Joe.

Comments and suggestion can be sent to This e-mail address is being protected from spam bots, you need JavaScript enabled to view it

Syntax for DeleteProfiles.vbs v1.9:

  cscript.exe DeleteProfiles.vbs [/H] [/E | /I <PROFILENAME>] [/C] [/R] [/D <DAYS>] [/L <FILENAME>] [/V]

  Command Line Options:
    /C                    : Write Log to the Console
    /D <Days>       : Delete Profiles Older than x Days
    /E <Profile>      : Exclude Profiles from Deletion
                           :   Wildcard * Supported. Use ',' or '|' as a Delimiter for
                           :   Multiple Entries. No Spaces Between Entries.
    /I <Profile>      : Only Delete Included Profiles (Wildcard * Supported)
                           :   Wildcard * Supported. Use ',' or '|' as a Delimiter for
                           :   Multiple Entries. No Spaces Between Entries.
    /L <FileName> : Create Log File
    /H                   : Help (This Screen)
    /R                   : Run Script in Read Only Mode (No System Changes)
    /V                   : Verbose Logging

A scheduled task can used to launch the script as the script will skip any profile hive that is loaded in memory.  While this works, it is recommended to launch this scripts as part of the system startup script (this can be set as a local policy or a GPO).  This allows the script to run on a freshly restarted system with no user profiles locked in memory.  It is also recommended that the systems that you run DeleteProfile.vbs against that you also install Microsoft’s UPHClean.  This will help those situations where the user hive is still loaded but the user is not logged onto the machine.

DeleteProfiles.vbs v1.9

'***************************************************************************
'*
'*  Delete Profiles script written by Joe Shonk ( This e-mail address is being protected from spam bots, you need JavaScript enabled to view it )
'*  Version 1.9
'*
'*  Syntax: cscript.exe DeleteProfiles.vbs [/H] [/E | /I <PROFILENAME>] [/C] [/R]
'*              [/D <DAYS>] [/L <FILENAME>] [/V]
'*
'*  This script is provided as-is, no warrenty is provided or implied.
'*  The author is NOT responsible for any damages or data loss that may occur
'*  through the use of this script.  Always test, test, test before
'*  rolling anything into a production environment.
'*
'*  This script is free to use for both personal and business use, however,
'*  it may not be sold or included as part of a package that is for sale.
'*
'*  A Service Provider may include this script as part of their service
'*  offering/best practices provided they only charge for their time
'*  to implement and support.
'*
'*  For distribution and updates go to: http://www.theshonkproject.com
'*
'***************************************************************************
On Error Resume Next

Const DeleteReadOnly = TRUE
Const HKEY_LOCAL_MACHINE = &H80000002
Const SIDExclusionList = "|S-1-5-18|S-1-5-19|S-1-5-20|"

'***************************************************************************
'*  To add your own profiles to the exclusion list simply add the
'*  account to the end of the strProfileExclusionList.  Note: Each account
'*  is delimited by a | (pipe) and is all lowercase
'*

Dim strProfileExclusionList
Dim strComputer, strLogFileName, strDocAndSettingsLocation
Dim strKeyPath, arrValueNames, arrValueTypes, arrSubKeys
Dim i, strHiveExclusionList, strHiveOpenSkipped, strHiveValue
Dim strSubKey, strGuid, strUserName, strProfileImagePath
Dim dwProfileExclusion, dwSIDExclusion, dwHiveOpenExclusion
Dim flgLogFile, flgWriteConsole, flgVerboseLog, flgAllowExecute, flgHelp
Dim dwArgCount, strNextArg, strCurrentArg, flgCustomExclusions, flgCustomExMatch
Dim strCustomExclusions, dateCurrentTime, flgCustomInclusions, strCustomInclusions
Dim flgCustomInMatch, flgExDateMatch, flgDateExclusion, dwDateExclusion

strComputer = "."
strProfileExclusionList = "|administrator|all users|default user|localservice|networkservice|public|ctx_smauser|ctx_cpuuser|ctx_cpsvcuser|ctx_streamingsvc|ctx_configmgr|"

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments

strLogFileName = ""
dateCurrentTime = now()
dwArgCount = 0
flgHelp = False
flgLogFile = False
flgCustomExclusions = False
flgWriteConsole = False
flgVerboseLog = False
flgAllowExecute = True

dwArgCount = objArgs.Count
For i = 0 to dwArgCount - 1
    strCurrentArg = lcase(objArgs(i))
    Select Case strCurrentArg
        Case "-v", "-verbose", "/v", "/verbose"
            flgVerboseLog = True
        Case "-c", "-console", "/c", "/console"
            flgWriteConsole = True
        Case "-r", "-readonly", "-read", "/r", "/readonly", "/read"
            flgAllowExecute = False
            flgWriteConsole = True
        Case "-l", "-log", "/l", "/log"
            If i < (dwArgCount - 1) then
                strNextArg = lcase(objArgs(i + 1))
                If (left(strNextArg, 1) <> "/") and (left(strNextArg, 1) <> "-") then
                    flgLogFile = True
                    strLogFileName = strNextArg
                    i = i + 1
                Else
                    wscript.echo "Warning: Log Switch Used but No Log Filename Specified."
                End if
            Else
                wscript.echo "Warning: Log Switch Used but No Log Filename Specified."
            End if
        Case "-e", "-exclude", "/e", "/exclude"
            If i < (dwArgCount - 1) then
                strNextArg = lcase(objArgs(i + 1))
                If (left(strNextArg, 1) <> "/") and (left(strNextArg, 1) <> "-") then
                    flgCustomExclusions = True
                    strCustomExclusions = replace(strNextArg, ",", "|", 1)
                    i = i + 1
                Else
                    wscript.echo "Error: Exclude Switch Used but no Argument Specified."
                    flgHelp = True
                End if
            Else
                wscript.echo "Error: Exclude Switch Used but no Argument Specified."
                flgHelp = True
            End if
        Case "-i", "-include", "/i", "/include"
            If i < (dwArgCount - 1) then
                strNextArg = lcase(objArgs(i + 1))
                If (left(strNextArg, 1) <> "/") and (left(strNextArg, 1) <> "-") then
                    flgCustomInclusions = True
                    strCustomInclusions = replace(strNextArg, ",", "|", 1)
                    i = i + 1
                Else
                    wscript.echo "Error: Include Switch Used but no Argument Specified."
                    flgHelp = True
                End if
            Else
                wscript.echo "Error: Include Switch Used but no Argument Specified."
                flgHelp = True
            End if
        Case "-d", "-days", "-day", "/d", "/days", "/day"
            If i < (dwArgCount - 1) then
                strNextArg = lcase(objArgs(i + 1))
                If (left(strNextArg, 1) <> "/") and (left(strNextArg, 1) <> "-") then
                    dwDateExclusion = cdbl(strNextArg)
                    i = i + 1
                    If (dwDateExclusion > 0) and (dwDateExclusion < 999999) then
                        flgDateExclusion = True
                    Else
                        flgHelp = True
                        wscript.echo "Error: Invalid Number of Days Specified."
                    End if
                Else
                    wscript.echo "Error: Day Switch Used but no Argument Specified."
                    flgHelp = True
                End if
            Else
                wscript.echo "Error: Day Switch Used but no Argument Specified."
                flgHelp = True
            End if
        Case "-h", "-help", "/h", "/help", "-?", "/?"
            flgHelp = True
        Case Else
            wscript.echo "Unrecognized option: " & objArgs(i)
            flgHelp = True
    End Select
next
If flgCustomExclusions and flgCustomInclusions then
    wscript.echo "Error: Cannot Specify a Custom Exclusion List with a Custom Inclusion List."
    flgHelp = True
End if

If flgHelp then
    wscript.echo "Help"
    wscript.echo ""
    wscript.echo "DeleteProfiles.vbs - v1.9"
    wscript.echo "-------------------------"
    wscript.echo ""
    wscript.echo "cscript.exe DeleteProfiles.vbs [/H] [/E | /I <PROFILENAME>] [/C] [/R]"
    wscript.echo "    [/D <DAYS>] [/L <FILENAME>] [/V]"
    wscript.echo ""
    wscript.echo "Command Line Options:"
    wscript.echo "  /C            : Write Log to the Console"
    wscript.echo "  /D <Days>     : Delete Profiles Older than x Days"
    wscript.echo "  /E <Profile>  : Exclude Profiles from Deletion"
    wscript.echo "                :   Wildcard * Supported. Use ',' or '|' as a Delimiter for"
    wscript.echo "                :   Multiple Entries. No Spaces Between Entries."
    wscript.echo "  /I <Profile>  : Only Delete Included Profiles (Wildcard * Supported)"
    wscript.echo "                :   Wildcard * Supported. Use ',' or '|' as a Delimiter for"
    wscript.echo "                :   Multiple Entries. No Spaces Between Entries."
    wscript.echo "  /L <FileName> : Create Log File"
    wscript.echo "  /H            : Help (This Screen)"
    wscript.echo "  /R            : Run Script in Read Only Mode (No System Changes)"
    wscript.echo "  /V            : Verbose Logging"
    wscript.echo ""
    wscript.quit
End if

If flgLogFile then Set objLogFile = objFSO.CreateTextFile(strLogFileName)

WriteHeader

'**********************************************************************************
'*   Enumerate a list of loaded Registry Hives.  Delimited by the | character
strHiveExclusionList = "|"
strHiveOpenSkipped = "|"
strKeyPath = "SYSTEM\CurrentControlSet\Control\hivelist"
objReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
For i=0 To UBound(arrValueNames)
    strHiveValue = trim(arrValueNames(i))
    strHiveExclusionList = strHiveExclusionList & Right(strHiveValue, len(strHiveValue) - instrrev(strHiveValue, "\")) & "|"
Next

'**********************************************************************************
'*   Enumerate a list of known profiles from the registry
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

'**********************************************************************************
'*   Parse through the Profile list and Delete the Registry entries and Files associated to the Profile
'*   Provided the profile is not listed in an Exclusion list
WriteLog "Checking Profile List"
WriteLog "---------------------"
If NOT flgAllowExecute then WriteLog "READ ONLY MODE. No changes made."
If flgDateExclusion then WriteLog "Purge Profiles Older than " & dwDateExclusion & " Days."
WriteLog ""

For Each subkey In arrSubKeys
    strSubKey = ""
    strGuid = ""
    strUserName = ""
    strProfileImagePath = ""
    strSubKey = trim(subkey)
    If (instr(SIDExclusionList, "|" & strSubKey & "|") = 0) and (strSubKey <> "") then
        strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strSubKey
        objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Guid", strGuid
        objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"ProfileImagePath", strProfileImagePath

        strUserName = Right(strProfileImagePath, len(strProfileImagePath) - instrrev(strProfileImagePath, "\"))
        WriteLog "Profile"
        If flgVerboseLog then WriteLog "  SID         : " & strSubKey
        If flgVerboseLog then WriteLog "  GUID        : " & strGuid
        WriteLog "  Profile Path: " & strProfileImagePath
        WriteLog "  UserName    : " & strUserName
    
        dwProfileExclusion = instr(strProfileExclusionList, "|" & trim(lcase(strUserName)) & "|")
        dwSIDExclusion = instr(strHiveExclusionList, "|" & strSubKey & "|")

    If flgCustomExclusions then
            flgCustomExMatch = TestCase(lcase(strUserName), lcase(strCustomExclusions))

            If flgCustomExMatch then
                strProfileExclusionList = strProfileExclusionList & trim(lcase(strUserName)) & "|"
                dwProfileExclusion = 1
            End if
        End if

    If flgCustomInclusions then
            flgCustomInMatch = TestCase(lcase(strUserName), lcase(strCustomInclusions))

            If flgCustomInMatch = 0 then
                strProfileExclusionList = strProfileExclusionList & trim(lcase(strUserName)) & "|"
                dwProfileExclusion = 1
            End if
        End if

        
    If flgDateExclusion then
            flgExDateMatch = 0
            If objFSO.FileExists(strProfileImagePath & "\NTUSER.DAT") then
                Set objFile = objFSO.GetFile(strProfileImagePath & "\NTUSER.DAT")
                flgExDateMatch = TestDateExclusion(objFile.DateLastModified, DateCurrentTime, dwDateExclusion)
            Else
                WriteLog "  NTUSER.DAT Does not Exist"
                If objFSO.FileExists(strProfileImagePath & "\NTUSER.MAN") then
                    WriteLog "  NTUSER.MAN Found"
                    Set objFile = objFSO.GetFile(strProfileImagePath & "\NTUSER.MAN")
                    flgExDateMatch = TestDateExclusion(objFile.DateLastModified, DateCurrentTime, dwDateExclusion)
                Else
                    WriteLog "  NTUSER.MAN Does not Exist"
                End if
            End if
            If flgExDateMatch then
                strProfileExclusionList = strProfileExclusionList & trim(lcase(strUserName)) & "|"
                dwProfileExclusion = 1
            End if
        End if
        If (dwProfileExclusion = 0) and (dwSIDExclusion = 0) then
            WriteLog "  Profile OK to Delete"
            If flgDateExclusion then WriteLog "  Profile Matches Age Requirement"
            If flgCustomInclusions and flgCustomInMatch then WriteLog "  Profile Matches Inclusion List"

            strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strSubKey
            DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

            strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\" & strSubKey
            DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

            strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\" & strSubKey
            DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

            strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\" & strSubKey
            DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

            If strGuid <> "" then
                strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\PolicyGuid\" & strGuid
                DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

                strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileGuid\" & strGuid
                DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
            Else
                WriteLog "  Guid is Blank, Deleting Registry Keys based of Guid has been skipped."
            End if

            If objFSO.FolderExists(strProfileImagePath) then
            WriteLog "  Folder Exists - Deleting"
                If flgAllowExecute then objFSO.DeleteFolder(strProfileImagePath), DeleteReadOnly
            Else
                WriteLog "  Folder Does not Exist"
            End if
        Else
            If dwProfileExclusion then
                WriteLog "  Profile not Deleted --- Username in Profile Exclusion List"
                If flgCustomExclusions and flgCustomExMatch then _
                  WriteLog "  Profile not Deleted --- Username Matched Custom Exclusion List"
                If flgCustomInclusions and (flgCustomInMatch = 0) then _
                  WriteLog "  Profile not Deleted --- Username Did not Match Custom Inclusion List"
                If flgDateExclusion and flgExDateMatch then _
                  WriteLog "  Profile not Deleted --- Profile is not Older than " & dwDateExclusion & " Days"
            End if
            If dwSIDExclusion then
                WriteLog "  Profile not Deleted --- User Hive is currently loaded"
                strHiveOpenSkipped = strHiveOpenSkipped & trim(lcase(strUserName)) & "|"
            End if
        End if
    End if
Next

'**********************************************************************************
'*   Get Document and Settings Directory Location from the Registry
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"ProfilesDirectory", strDocAndSettingsLocation
WriteLog ""
WriteLog "Documents and Settings Path: " & strDocAndSettingsLocation
WriteLog ""
WriteLog "Checking For Orphaned Profile Directories"
WriteLog "-----------------------------------------"
Set objFolder = objFSO.GetFolder(strDocAndSettingsLocation)
Set colSubfolders = objFolder.Subfolders

'**********************************************************************************
'*   Parse through the directory a check For orphaned profile folders and Delete
For Each objSubfolder in colSubfolders
    strUserName = lcase(Right(objSubfolder.Path, len(objSubfolder.Path) - instrrev(objSubfolder.Path, "\")))
    dwProfileExclusion = instr(strProfileExclusionList, "|" & trim(lcase(strUserName)) & "|")
    dwHiveOpenExclusion = instr(strHiveOpenSkipped, "|" & trim(lcase(strUserName)) & "|")
    If (dwProfileExclusion = 0) and (dwHiveOpenExclusion = 0) then
        WriteLog "Deleting Orphaned Profile Directory: " & objSubfolder.Path
        If flgAllowExecute then objFSO.DeleteFolder(objSubfolder.Path), DeleteReadOnly
    Else
        If dwHiveOpenExclusion then
          WriteLog "Hive Loaded      -- Skippped Delete: " & objSubfolder.Path
        End if
        If dwProfileExclusion then
            WriteLog "Profile Excluded -- Skippped Delete: " & objSubfolder.Path
        End if
    End if
Next


WriteFooter
If flgLogFile then objLogFile.Close
objReg = Nothing
objFSO = Nothing
objArgs = Nothing

'**********************************************************************************
'*   Deletes All Subkeys and Values within a Given Registry Key
Sub DeleteKey(dwHiveType, strDeleteKeyPath)
    Dim dwReturn, arrDeleteSubKeys, strDeleteSubKey
    dwReturn = objReg.EnumKey(dwHiveType, strDeleteKeyPath, arrDeleteSubKeys)
    If (dwReturn = 0) And IsArray(arrDeleteSubKeys) Then
        For Each strDeleteSubKey In arrDeleteSubKeys
            DeleteKey dwHiveType, strDeleteKeyPath & "\" & strDeleteSubKey
        Next
    End if
    If flgAllowExecute then objReg.DeleteKey dwHiveType, strDeleteKeyPath
    If flgVerboseLog then WriteLog "  Deleting: " & strDeleteKeyPath
End Sub


'**********************************************************************************
'*   Test a List of Wildcard Items Against a Value
Function TestCase(strTestCase, strWildCardTests)
    TestCase = 0

    dwAllItems = 0
    dwSoftLeft = 0
    dwSoftRight = 0

    arrWildCards = split(strWildCardTests, "|")

    For each strWildCard in arrWildCards
        If strWildcard = "*" then
            dwAllItems = 1
        Else
            If left(strWildcard, 1) = "*" then
                dwSoftLeft = 1
                strWildcard = right(strWildcard, len(strWildcard) - 1)
            End if
            If right(strWildcard, 1) = "*" then
                dwSoftRight = 1
                strWildcard = left(strWildcard, len(strWildcard) - 1)
            End if
        End if    
        If strWildcard = "" then dwAllItems = 1

        If dwAllItems then
            TestCase = 1
        Else
            dwLeftOk = 0
            dwRightOk = 0
            dwOffSet = instr(strTestCase, strWildcard)

            If dwOffSet then
                If (dwSoftLeft = 0) and (dwOffSet = 1) then dwLeftOk = 1
                If dwSoftLeft then dwLeftOk = 1
            End if
            dwRightOffSet = len(strTestCase) - dwOffset - len(strWildcard) + 1
            If dwRightOffSet = 0 then dwRightOk = 1
            If dwRightOffset > 0 and dwSoftRight = 1 then dwRightOk = 1
            If dwLeftOk and dwRightOk then TestCase = 1
        End if
    Next
End Function

'**********************************************************************************
'*  Test Profile Date Against the Current Date.  Then Compare Against out Value   
Function TestDateExclusion(dateTestCase, dateTestCurrentTime, dwTestNumDays)
    TestDateExclusion = 0
    dwNumDays = DateDiff("d", dateTestCase, dateTestCurrentTime)
    If dwNumDays <= dwTestNumDays then TestDateExclusion = 1
    If flgVerboseLog then WriteLog "  Profile Age : " & dwNumDays & " Days"
End Function

'**********************************************************************************
'*   Log Header
Sub WriteHeader
    WriteLog "---"
    WriteLog "-- Profile Deletion Script Executed: " & dateCurrentTime
    WriteLog "---"
    WriteLog ""
End Sub

'**********************************************************************************
'*   Log Footer
Sub WriteFooter
    WriteLog ""
    WriteLog "---"
    WriteLog "-- Profile Deletion Script Completed."
    WriteLog "---"
End Sub

'**********************************************************************************
'*   Write String to Log File
Sub WriteLog(strString)
    If flgLogFile then objLogFile.Writeline strString
    If flgWriteConsole then wscript.echo strString
End Sub

Comments
Add New RSS
fredrik   |2008-08-29 11:10:44
awesome, wildcard support
David   |2008-09-03 22:32:13
Thank you Joe! It's everything I need.
I'll be testing it over the next few
weeks.
Randall   |2008-09-19 00:46:07
Good to see the profiles excluded by the first round of testing are then
excluded in the orphan check. It took a little while to get into the flow of
the code and find where I need to make the neccessary changes. I already
completed a modification to 1.8 to do a SID check against the domain to look for
deleted accounts. I will send it to you so you can incorrporate it into your
next version
Stephen   |2008-09-28 19:04:30
Excellent script. I've got a question though.

On our terminal servers there is
a key ( plus subtree ) in registry

\HLM\Software\Windows
NT\Current Version\winlogon\

that is delete by delprof.exe and the
system tool that is not deleted
by your script. Any thoughts as to whether
this too should be deleted?
Stephen   |2008-09-28 19:09:41
Oops, the SID disappeared from that key. It should have
been

HLM\Software\WindowsNT\Current Version\winlogon\SID
Wood   |2008-10-24 13:29:08
Has anyone run this script on Vista? I am having some problems getting it to
work properly. It will delete the registry data, but everything is left in the
registry. If anyone has any ideas, I would greatly appreciate them.
Thanks
Pat   |2008-12-10 08:07:53
Try to run the vbscript as an administrator in vista, unless you are logged in
already as a vista administrator.
Wood   |2008-12-10 10:15:30
Have you gotten the script to run properly in Vista? I am running it from the
admin account. I have even run the script as administrator from an admin
account. I do think it is a permissions issue as the script thinks that it has
deleted the orphaned directories, but they are still present.
Eric   |2008-12-21 21:12:58
I had the same problems at Vista as well.
The logs did mention that the profiles
being deleted, but none of the personal folder nor registry being deleted.
Jarud   |2009-02-13 07:43:08
It did not work properly for me either. I ran it will admin privileges and the
logs indicated the profiles were deleted, but they were not deleted.
Nik  - Thanks   |2008-12-18 07:55:20
great script - thanks very much!
Allan Trudgeon   |2009-01-06 17:00:04
Firstly, excellent scripting!

But...

It needs an extra piece of code to
provision the exclusion of the ASPNET profile which is in a slightly different
format.

ie. %SystemDrive%\Documents and Settings\\ASPNET

As the
script stands, it looks like (by using read-only mode to test) that it will
exclude the profile initially (based on the username being in the exclusion
list), but flags the folder as an orphan because doesn't match srtUserName
(ASPNET)
Allan Trudgeon   |2009-01-06 17:02:09
Sorry used greater than and less than symbols in my last post...

Firstly,
excellent scripting!

But...

It needs an extra piece of code to
provision the
exclusion of the ASPNET profile which is in a slightly different
format.

ie.
%SystemDrive%\Documents and Settings\"ServerName"\ASPNET

As
the
script stands, it looks like (by using read-only mode to test) that it
will
exclude the profile initially (based on the username being in the
exclusion
list), but flags the folder as an orphan because "ServerName"
doesn't match srtUserName
(ASPNET)
Joe  - ASPNET     |2009-01-07 13:48:00
Allan,

Thanks for the feedback! One way to accomplish what you're asking is to
use the /E switch to exclude the Profilename/Directory combination.

For
Example:

cscript.exe //nologo deleteprofiles.vbs /E %COMPUTERNAME%,ASPNET

You
can also use this trick to exclude other Directories in Doc and Settings that
otherwise would be flagged as orphaned. I know a lot of places make a copy of
the Default User folder before making modifications to it. Since the Copy does
not have registry value associated with it, it is consider orphaned and deleted.
The exclusion list can specify the folder name instead of the username.

Joe
Jochem  - Thanks   |2009-02-05 07:29:36
Great Script!!

to quote 'the Cars' it was 'Just what I needed'

greetings from
Holland.
Sandy  - Citrix questions   |2009-02-06 16:29:10
Hello Joe,

I guess we have a similar quandry here. We have roaming profiles on
multiple Citrix servers (I am new here, don't know why they did it exactly) as
well as the profiles are mapped to DFS shares which are mirrored.

At any rate,
applications fail if the profile gets corrupt. Right now we have to log on to
each Citrix server that has the roaming profile (we have a VB script to show
which servers have the profile and which don't) and manually delete them via the
Properties of the Computer -> Advanced -> User profiles Settings button ->
select -> Delete button.

My questions are as such: Does your script perform
the exact same function as the Windows user profile delete button and two: can
your script be easily used to remotely touch a list of servers to perform the
same functions on one profile.

It's a bit of a toughy but we're hitting a wall
here.
Joe Shonk  - Citrix Questions     |2009-02-17 10:24:34
Hello Sandy,

To answer your questions:

Yes, the script performs the same
function as if you were to delete the profile by using the GUI

Second, you can
run the script remotely using PSEXEC.EXE as sysinternals tool that is now owned
by Microsoft. You could write a simple CMD script that loops through a list of
server names and runs PSEXEC.EXE w/ the DeleteProfiles.vbs script. You can also
use the /I to limit the profile deletion to a single object.

Joe
Alex  - thank you   |2009-02-13 01:28:30
this is a great job here!

I just have a problem with hidden folder
"Default" which I must keep, but it's always deleted even with option
"/E Default".

am I doing something wrong?

thanks again
Joe Shonk  - Default User     |2009-02-13 08:46:54
The exclusion line in the script above is really long (I'll split in the next
version) so the website word wraps and breaks the line where the space is in
default user. Make that this line:

strProfileExclusionList =
"|administrator|all users|default
user|localservice|networkservice|public|ctx_smause
r|ctx_cpuuser|ctx_cpsvcuser|ctx_streamingsvc|ctx_c onfigmgr|"

is really one
line and that there is a space between default and user. It should look
something like
|default user|

To exclude using the /E switch the syntax would
be /E "default user"

Joe
Kurt  - Fails to run   |2009-06-24 10:58:47
The script fails to run on two out of four of my Citrix Servers, with no errors.
Any ideas.
Stephen  - I have a question   |2009-02-18 14:30:51
Does this script take the local users out of the manage area? Also, I dont want
it to take domain profiles, it wont do that will it?
Alex  - Default User again   |2009-02-23 01:20:25
hello Joe,

thanks for the reply.

I've checked and the strProfileExclusionList
line is 1 piece with no space.
But the hidden folder "Default" is always
deleted , Public is not, for instance.

I'm on vista business

what else
could I check?
Joe  - Default User     |2009-02-23 08:03:33
I think I've got it now that I have Vista machine up and run.

In the
strProfileExclusionList = line append the follow to the end

"|default
user|default|"

There needs to be a space between the default and user,
there needs to be a pipe delimiter | before and after, and the entries need to
be all lowercase.

Joe
Alex   |2009-02-24 01:38:05
it seems to be working with |default user|default| at the end !
I already tried
but with first letter in uppercase and didn't work.

thanks again
John   |2009-04-13 21:52:13
I've been trying to get this working in Vista as well.

It appears to run, and
the registry appears to get deleted but not the local files. Am I missing
anything simple?

I've added the tweaks above and am running this as a domain
administrator (tried both running directly on the machine and via a startup
script).

Thanks,
John
Anonymous   |2009-04-30 01:15:09
Excellent !

Saved me lots of time reinventing the wheel !
BTW,
I found a Typo in the code:

Line 59: flgLogFile = Flase should be
flgLogFile = False

Some Advise :
Turn on the Option Explicit
Comment
the "On Error Resume Next" line and debug the the code through all the
lines.
You will then catch many Errors that one will miss.
Joe Shonk  - Thanks     |2009-04-30 07:57:32
Good eye! I went ahead and update the block of code.

Joe
Anonymous  - network administrator   |2009-05-13 12:01:44
Is anyone else having troubles getting this to remove the folders in
C:\Users? I was able to get them removed by a combination of this script
and some .net code (using system.io.directoryinfo):

Dim di As New
System.IO.DirectoryInfo(args(0))
di.Delete(True)


...but don't like the idea
of needing multiple scripts/applications for this simple task. If I'm not
missing something and there is no easier way I may reverse engineer this script
into a .net application that can be called from a startup script.

Any
information is greatly appreciated. Thanks.
KGodoy  - Error when running script   |2009-07-09 11:11:14
Did I miss a step?

I'm typing the following:

C:\>cscript
deleteprofiles.vbs /E kkg

I get the following error:

deleteprofiles.vbs(1, 1)
Microsoft VBScript compilation error: Invalid character
KGodoy  - I found it   |2009-07-09 11:31:55
Apperantly if I copy and paste the code into notepad, it inserts text that
doesn't show up on notepad. Even if I use Notepad++ and tell it to save it as
ANSI, it still adds the extra characters. I was able to open it in EDIT from the
command prompt and the culprit characters showed up, I saved it and now I'm
running it on a test computer filled with old profiles. No errors after 5
mintues, so I'm assuming it's good. Thanks for the script!!!
Mike  - Network Manager   |2009-07-24 05:57:56
Great script! Thanks for sharing.

It seems that some profiles are not
deleted by the script. When I go back and manually delete the folders, The
warming pops up saying the folder 'contains items whose name is too long for the
recycle bin".

Anyone else get that?
Roy  - Can't get folders removed from users either   |2009-08-11 05:37:00
Thanks for this great script.

As others have mentioned, I'm also not getting
the folders inside the users folder to delete with vista. Is there any update to
this issue? What am I missing? Any suggestions?

Thanks.
Richard Meza  - System Analyst   |2009-12-04 11:24:10
Has anyone responded to your solution regarding deleteprofile NOT deleting
c:\User\ folders for Windows 7?

Regards.

-R
MBlinde   |2009-08-25 07:49:07
Is anyone running this on server 2008 yet?
John   |2009-09-11 10:45:10
here is the cmd file I am trying to run, it reports every profile on exlcusion
list.

cscript.exe E:\Temp\DeleteProfiles.vbs /R /C /L
C:\WINDOWS\system32\LogFiles\delet eprofiles.log /D 30 /E


"|administrator|all users|all
users.bak|ctx_cpsvcuser|ctx_smauser|ctx_streamings vc|default


user|packager|localservice|networkservice|svc_
ctxpbm|citrixadmin|raadmin|mastercyl|reboot|nettim
e|uh3hkai|

is78301|ds064|"
DiLupo  - When there is no such profile   |2009-11-30 05:29:49
Hi Joe,

First, compliments for an effective script. Now a question... How can
I get a notification that the script has failed when using the /I option and
typing a profile name which is not actually on the machine (for instance when
I've made a typo). The current output log is a bit to much for when you are
using the script on multiple machines with quite a big number of profiles to
remove.

Thanks!

DiLupo
Richard Meza   |2009-12-03 16:04:16
I've been trying to get this working in Windows 7 as well.

It appears to run,
and
the registry appears to get deleted, but not the local profile folders. Am
I missing
anything simple?


Thanks,
Richard
Bobby McCracken   |2010-01-28 06:55:00
THANK YOU!

Great script. Thank you so much for your work. This is very helpful to
keep our computers clean. With the exclusion list (with wildcard
supports) this script runs perfectly in our environment. Why can't
Microsoft implement such things originally? Keep it up! Best regards.
Ben  - Script not found   |2010-03-01 06:52:33
The script looks amazing, and definitely has some major ability to fix some of
our problems over here. However I'm unable to get altiris 6.9 to see the
script. The script is placed both in a network drive and on Altiris' desktop
for my account and the admin's account. I have domain admin rights, so it's not
a rights/permissions issue. The error Altiris throws an error saying that the
script at both locations, below, are not found. It doesn't matter if I run it
with switches or not.

cscript.exe
C:\Users\\Desktop\DeleteProfiles.v bs /E /I *.* /L
C:\ProfileLog.log /R /V
cscript.exe \\\tech-share\New
Software\Scripts\Delete Profiles\DeleteProfiles.vbs
Joe  - Script   |2010-03-01 07:58:51
Hello,
It's not about the rights that you have to run the script but more of
which right the Altiris service account has to run the script. Make sure that
account has access to the network share and to the local machine.

Joe
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 
Next >