#68787 - 2002-07-31 10:56 PM
get @pwage from user list and send notification e-mail.
|
Jake
Fresh Scripter
Registered: 2001-11-14
Posts: 26
|
I have a list of users account (net use /domain >user.txt) which I'm trying to get the password age for. If the age is greater than X days, send a SMTP message to the user to change their password. I have the concept down but can't seem to get the coding right. Kix4.02 NT4 enviroment.
|
|
Top
|
|
|
|
#68789 - 2002-08-01 12:00 AM
Re: get @pwage from user list and send notification e-mail.
|
Jake
Fresh Scripter
Registered: 2001-11-14
Posts: 26
|
Thanks for the response, that's only part of what I'm trying to accomplish. We have 2 domains (Primary and Secondary), users have accounts in both domains, they primarily login to the Primary and rarely the Secondary domain. I have a users account list for the Secondary domain which looks like this: [LIST] usera userb userc userd userf etc... [/LIST] I want to get the password age for all accounts on the list; if account(s) is over X days, then send a e-mail to user's e-mail address (which is username@company.com)
|
|
Top
|
|
|
|
#68791 - 2002-08-01 01:11 AM
Re: get @pwage from user list and send notification e-mail.
|
Jake
Fresh Scripter
Registered: 2001-11-14
Posts: 26
|
I can't do it at login because users lock (for a long time) their workstations instead of logging off. I know how to get a list of users for the domain, but how do I use that list to check for password age and send e-mail?? user.txt: usera userb userc userd usere etc...
code:
$maxpwage=10 open users.txt realine(1) while $rc=0 extract usera from line1 If usera password > $maxpwage send e-mail to usera endif readline(1) loop
|
|
Top
|
|
|
|
#68793 - 2002-08-01 01:35 AM
Re: get @pwage from user list and send notification e-mail.
|
Jake
Fresh Scripter
Registered: 2001-11-14
Posts: 26
|
Would you be so kind as to post or point in the direction of your code ?
|
|
Top
|
|
|
|
#68795 - 2002-08-01 03:07 AM
Re: get @pwage from user list and send notification e-mail.
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
you will want to use ADSI for this....
here is something to get you sarted on the password age bit...
code:
$usernamefromfile = @userid
$user = getobject("WinNT://@domain/$usernamefromfile") $temp = split($user.PasswordExpirationDate,"/") $temp[2] = substr($temp[2],1,4) if len($temp[0]) <> 2 $temp[0] = "0" + $temp[0] endif $expdate = $temp[2] + "/" + $temp[0] + "/" + $temp[1]
? "number of days until " + $user.name + " will expire is " + val(serialdate($expdate) - serialdate(@date)) + " (" + $user.PasswordExpirationDate + ")"
as for email... BLAT is a very good program, i am guessing that along with a list of user names you also have a list of email addresses?
Bryce [ 01 August 2002, 03:17: Message edited by: Bryce ]
|
|
Top
|
|
|
|
#68796 - 2002-08-01 03:12 AM
Re: get @pwage from user list and send notification e-mail.
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Sorry! in my example i am using the UDF SerialDate() [ 01 August 2002, 03:13: Message edited by: Bryce ]
|
|
Top
|
|
|
|
#68797 - 2002-08-01 03:59 AM
Re: get @pwage from user list and send notification e-mail.
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Jake,
You should be able to snag some ideas from this post -
Password expiration for a service account
HTH,
Kent
|
|
Top
|
|
|
|
#68798 - 2002-08-01 07:48 PM
Re: get @pwage from user list and send notification e-mail.
|
Jake
Fresh Scripter
Registered: 2001-11-14
Posts: 26
|
Bryce, I ran your code and quote: the number of days the account will expire is -730447
, which is not correct since the accounts have a max age of 60. quote: i am guessing that along with a list of user names you also have a list of email addresses?
Once I figure out how to trim the user name from the user list : usera userb userc
Use that variable to send e-mail (i.e. $x=username, $x@company.com)
Kent, I have taken a look at your script but I can not make heads or tails out of it, way over my head. Thanks for the link.
|
|
Top
|
|
|
|
#68800 - 2002-08-01 08:46 PM
Re: get @pwage from user list and send notification e-mail.
|
Jake
Fresh Scripter
Registered: 2001-11-14
Posts: 26
|
O.K. I have extracted informations from Kent's post Password expiration for a service account to calculate the days left before the password expires. Even though I don't understand the language or code code:
$ldomain = @domain $lstrusername = "@username" ;$userobj = GetObject("LDAP://cn=ntdoc,ou=Users,ou=mybusinessOU,ou=cala,dc=MyCompany,dc=com") $userobj = GetObject("WinNT://$LDomain/$lstrUserName") $pwexpire = $userobj.passwordexpirationdate ?"UserName: " + $userobj.name ?"UserPasswordExpires: " + $pwexpire
$tt = SPLIT($pwexpire," ") $mdy = SPLIT($tt[0],"/") $expiredatearray = $mdy[2],$mdy[0],$mdy[1] $currentdatearray = "@YEAR","@MONTHNO","@MDAYNO" FUNCTION CalcDayofYear($ymdarray) ; Only works on non-millenium years after 2000. $calendar = 31,28,31,30,31,30,31,31,30,31,30,31 IF VAL($ymdarray[0]) & 1 $ly = 0 ; leap year calculations ELSE IF (Val($ymdarray[0])/2) & 1 $ly = 0 ELSE $ly = 1 ENDIF ENDIF $calendar[1] = $calendar[1] + $ly $mdays = 0 FOR $m = 0 TO (Val($ymdarray[1]) -2) $mdays = $mdays + $calendar[$m] NEXT $calcdayofyear = $mdays + $ymdarray[2] ENDFUNCTION
$diffyears = VAL($expiredatearray[0]) - VAL($currentdatearray[0]) IF $diffyears > 0 $yearstodays = 0 FOR $countyear = VAL($currentdatearray[0]) TO (VAL($expiredatearray[0])-1) $acountyear = $countyear,"12","31" $yearstodays = $yearstodays + CalcDayofYear($acountyear) NEXT ENDIF
$daystoexpire = CalcDayofYear($expiredatearray) - CalcDayofYear($currentdatearray) + $yearstodays ?"Number of Days till password expires: " + $daystoexpire
Can someone show me how to extract the user name from a text file and feed it into the code above? example text file: usera userb userc userd usere userf userg userh etc.....
Thanks for everyone's help so far.
|
|
Top
|
|
|
|
#68801 - 2002-08-01 08:49 PM
Re: get @pwage from user list and send notification e-mail.
|
Jake
Fresh Scripter
Registered: 2001-11-14
Posts: 26
|
I am using the net users /domain >users.txt to get the list.
|
|
Top
|
|
|
|
#68804 - 2002-08-01 09:34 PM
Re: get @pwage from user list and send notification e-mail.
|
Jake
Fresh Scripter
Registered: 2001-11-14
Posts: 26
|
This is really weird. If I use this code with a given username (i.e. guest), it works fine. code:
$ldomain = @domain $lstrusername = "guest" $userobj = GetObject("WinNT://$LDomain/$lstrUserName") $pwexpire = $userobj.passwordexpirationdate ?"UserName: " + $userobj.name ?"UserPasswordExpires: " + $pwexpire
$tt = SPLIT($pwexpire," ") $mdy = SPLIT($tt[0],"/") $expiredatearray = $mdy[2],$mdy[0],$mdy[1] $currentdatearray = "@YEAR","@MONTHNO","@MDAYNO" FUNCTION CalcDayofYear($ymdarray) ; Only works on non-millenium years after 2000. $calendar = 31,28,31,30,31,30,31,31,30,31,30,31 IF VAL($ymdarray[0]) & 1 $ly = 0 ; leap year calculations ELSE IF (Val($ymdarray[0])/2) & 1 $ly = 0 ELSE $ly = 1 ENDIF ENDIF $calendar[1] = $calendar[1] + $ly $mdays = 0 FOR $m = 0 TO (Val($ymdarray[1]) -2) $mdays = $mdays + $calendar[$m] NEXT $calcdayofyear = $mdays + $ymdarray[2] ENDFUNCTION
$diffyears = VAL($expiredatearray[0]) - VAL($currentdatearray[0]) IF $diffyears > 0 $yearstodays = 0 FOR $countyear = VAL($currentdatearray[0]) TO (VAL($expiredatearray[0])-1) $acountyear = $countyear,"12","31" $yearstodays = $yearstodays + CalcDayofYear($acountyear) NEXT ENDIF
$daystoexpire = CalcDayofYear($expiredatearray) - CalcDayofYear($currentdatearray) + $yearstodays ?"Number of Days till password expires: " + $daystoexpire
But if I insert the above code in Lonkero code: code:
break on $nul=open(1,"c:\scriptlogic\kix2001.402\users.txt") $line=readline(1) while not @error for each $user in split($line) ?$user ;******************************************************************************* ;Calculating account expire date
$ldomain = @domain $lstrusername = $user $userobj = GetObject("WinNT://$LDomain/$lstrusername") $pwexpire = $userobj.passwordexpirationdate ?"UserName: " + $userobj.name ?"UserPasswordExpires: " + $pwexpire
$tt = SPLIT($pwexpire," ") $mdy = SPLIT($tt[0],"/") $expiredatearray = $mdy[2],$mdy[0],$mdy[1] $currentdatearray = "@YEAR","@MONTHNO","@MDAYNO" FUNCTION CalcDayofYear($ymdarray) ; Only works on non-millenium years after 2000. $calendar = 31,28,31,30,31,30,31,31,30,31,30,31 IF VAL($ymdarray[0]) & 1 $ly = 0 ; leap year calculations ELSE IF (Val($ymdarray[0])/2) & 1 $ly = 0 ELSE $ly = 1 ENDIF ENDIF $calendar[1] = $calendar[1] + $ly $mdays = 0 FOR $m = 0 TO (Val($ymdarray[1]) -2) $mdays = $mdays + $calendar[$m] NEXT $calcdayofyear = $mdays + $ymdarray[2] ENDFUNCTION
$diffyears = VAL($expiredatearray[0]) - VAL($currentdatearray[0]) IF $diffyears > 0 $yearstodays = 0 FOR $countyear = VAL($currentdatearray[0]) TO (VAL($expiredatearray[0])-1) $acountyear = $countyear,"12","31" $yearstodays = $yearstodays + CalcDayofYear($acountyear) NEXT ENDIF
$daystoexpire = CalcDayofYear($expiredatearray) - CalcDayofYear($currentdatearray) + $yearstodays ?"Number of Days till password expires: " + $daystoexpire ;*************************************** ;done calculating
next $line=readline(1) loop exit
I receive the following error: code:
Script Error: unknown command! $pwexpire = $userobj.passwordexpirationdate
[ 01 August 2002, 21:45: Message edited by: Jake ]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 293 anonymous users online.
|
|
|