Page 1 of 1 1
Topic Options
#149899 - 2005-10-13 02:58 PM deleting old users
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
I'm trying to create a script that'll run on a dialy basis which will delete any user that was disabled 30 days ago. I put together a dsquery statement that'll get me a list of disabled users with the date the user object was last modified, but I can't figure out a way to delete only users that were modified 30 or more days ago...I can pipe the results to dsmod and delete those users...but again that'll be all disabled users and not ones that have been disabled for 30 days. Maybe there's even a way to do it in kix alone without dsquery that I dont' know about...here's the dsquery command I'm using:


dsquery * domainroot -filter
"(&(objectCategory=Person)(objectClass=User)(sAMAccountName=*)(!name=User
Template)(userAccountControl:1.2.840.113556.1.4.803:=2))" -attr
sAMAccountName whenChanged -limit 999999

Thanks!

Top
#149900 - 2005-10-13 03:55 PM Re: deleting old users
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
You could use fnLDAPQuery() to replace dsquery.exe, then use fnDateTime() to convert the whenChanged date to a KiXtart formatted date, then use DateCalc() or fnDateDiff() to calculate how many days it has been since the account was last modified.
Top
#149901 - 2005-10-13 05:45 PM Re: deleting old users
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
I'm not sure how to go about passing the fnldapquery results to fndatetime()...here's my bit of code:

Code:

$aAttributes = "Name", "whenChanged"
$sADsPath = "LDAP://ou=disabled users,dc=xxxxx,dc=com"
$strFilter = "(&(objectClass=User)(Name=*))"

$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"Name")
@ERROR " | " @SERROR ?

For $c = 0 to Ubound($aResults)
For $r = 0 to UBound($aResults,2)
$aResults[$c,$r] ?
$fnDateTime($aResults[$c,$r])?
Next
?
Next



the $fnDateTime() returns the same exact values I pass to it, so I get results that look like:

Jim Smith
Jim Smith
6/27/2005 8:02:48 PM
6/27/2005 8:02:48 PM

Top
#149902 - 2005-10-13 07:12 PM Re: deleting old users
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
fnDateTime() is a function, not a variable.

Code:

$aAttributes = "Name", "whenChanged"
$sADsPath = "LDAP://ou=disabled users,dc=xxxxx,dc=com"
$strFilter = "(&(objectClass=User)(Name=*))"

$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"Name")
@ERROR " | " @SERROR ?

; For Next loop to enumerate through each row of data
For $r = 0 to Ubound($aResults)
$aResults[$r,0] ? ; Print the name attribute
fnDateTime($aResults[$r,1]) ? ; Convert the localized DateTime to KiXtart DateTime
?
Next


Top
#149903 - 2005-10-13 07:59 PM Re: deleting old users
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
oh lol I didn't even realize I put the $ in there...thanks, I've been looking at the screen for too long.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.154 seconds in which 0.096 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org