Code to Delete Unused Profiles

This topic shows how to use the [ProfileSystem.date_last_changed] property in the default schema to delete profiles that have been unused for some arbitrary time.

The sample script below deletes user-profile objects that were last changed on October 4 2000 or before. The date is expressed in the form {d '2001-10-5'}.

To use the script, you will need to supply the correct server name, myserver, and Password.

Dim strDSN
Dim strSQL
Dim objCN

Set objCN = WScript.CreateObject("ADODB.Connection")
Set objRS = WScript.CreateObject("ADODB.Recordset")

strDSN = "Provider=commerce.dso.1;Data Source = _
  MSCOP://INPROCCONNECT/Server=myserver:" & _
  "Catalog=Profile Definitions:Database = Retail_commerce:" & _
  " Trusted_Connection=Yes:"
objCN.Open strDSN

strSQL = "
DELETE FROM [UserObject] 
WHERE [ProfileSystem.date_last_changed] < {d '2001-10-5'}
"

objCN.Execute(strSQL)

Set objCN = Nothing

Copyright © 2005 Microsoft Corporation.
All rights reserved.