Re: Delete old profiles by Gino
Gino
Sat Oct 14 19:32:36 CDT 2006
Hope this helps.
Watch for line Wrap.
Use on test machine first. Let me know how it worked.
'Delete User Profiles Older Than 30 Days
'except Administrators, ASPNET, and Speacial Profiles
strValueName = "ProfileImagePath"
strComputer = "."
'***Enum for HKeyLocalMachine
Const HKEY_LOCAL_MACHINE = &H80000002
'***Create objects
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'***Get the SID for all user profiles from Registry
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
'***Iterate thru collection of SIDs getting path to
'***user profile, minus speacial profiles and sytem template
'***and copy to dictionary object.
i = 1
For Each objSubkey In arrSubkeys
stringLen = Len(objSubkey)
if stringLen > 12 then
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE, _
strSubPath,strValueName,strValue
objDictionary.add i, strValue
i = i + 1
end if
Next
'***Iterate thru dictionary object and edit full path to
'***"\UserProfile" minus "\Administrator" and "\ASPNET"
'***Then delete all UserProfiles older than 30 days.
For j = 1 to objDictionary.count
Set objFile = objFSO.GetFile(objDictionary.item(j)&"\NTUSER.DAT")
days = DateDiff("d", objFile.DateLastModified, Date)
folderPath = objFile.ParentFolder
strLength = InStrRev(folderPath, "\")
subFolder = Mid(folderPath, strLength)
if subFolder <> "\Administrator" then
if subFolder <> "\ASPNET" then
if days > 30 then
objFSO.DeleteFolder(objFile.ParentFolder)
end if
end if
end if
Next
'*** Release memory
Set objRegistry = Nothing
Set objDictionary = Nothing
Set objFSO = Nothing
"Andrea" <Andrea@discussions.microsoft.com> wrote in message
news:B7D1890B-AA93-4A11-B3BE-A571A643E4A2@microsoft.com...
> Wasn't on purpose. Site gave me an error, telling me the information could
> not be posted.
> --
> Andrea
>
>
> "McKirahan" wrote:
>
>> "Andrea" <Andrea@discussions.microsoft.com> wrote in message
>> news:D4D64DFF-E172-4C23-94EE-E57691ED03A6@microsoft.com...
>> > in need of a vbscript deleting all old profiles older than 30 days and
>> > exlcude particular profiles, such as Administrator.
>>
>> Three posts in 15 minutes!
>> If someone helps you will you stop?
>>
>>
>>