Hello......
how can I set the account expiration date to the date on which the
account created or changed or even the date on which the password last
set plus number of days?.
And how can I display the account expiration date and be readeable as
a good format.
Thanks in advance...
See tip 8079 » How can I convert a long integer FILETIME, like Active Directory attributes lastLogon and pwdLastSet, to a date and time?
in the 'Tips & Tricks' at
http://www.jsifaq.com
See tip 77147714 » What attribute names can I use with the user filtered dsquery command?
See:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set q1=dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User))"
set q2= -attr sAMAccountName distinguishedName accountExpires lastLogon lastLogonTimestamp whenChanged whenCreated
set q3= -L -limit 0
set qry=%q1%%q2%%q3%
for /f "Tokens=1*" %%a in ('%qry%') do (
if /i "%%a" EQU "sAMAccountName:" set dtX=Never&set dtL=Never&set dtLLTS=Never
if /i "%%a" EQU "sAMAccountName:" set user=%%b
if /i "%%a" EQU "distinguishedName:" set dn="%%b"
if /i "%%a" EQU "accountExpires:" if "%%b" NEQ "" call cvtfiletime %%b dtX
if /i "%%a" EQU "lastLogon:" if "%%b" NEQ "" call cvtfiletime %%b dtL
if /i "%%a" EQU "lastLogonTimestamp:" if "%%b" NEQ "" call cvtfiletime %%b dtLLTS
if /i "%%a" EQU "whenChanged:" set wChg=%%b
if /i "%%a" EQU "whenCreated:" set wCrt=%%b&@echo !user! !dn! !dtX! !dtL! !dtLLTS! !wChg! !wCrt!
)
endlocal