Page 2 of 2 <12
Topic Options
#68807 - 2002-08-01 09:52 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
I've try that
code:
 
break on
$nul=open(1,"c:\scriptlogic\kix2001.402\users.txt")
$line=readline(1)
while not @error
for each $user in split($line)
gosub calculate
next
$line=readline(1)
loop
exit

:calculate
Kent's code here

and received the same error. Unless, I'm doing wrong?

Additional comment: Kent's code works perfectly if a specified username is given. It generates the error when a variable ($user) is used for the username..

[ 01 August 2002, 21:58: Message edited by: Jake ]

Top
#68808 - 2002-08-02 06:20 AM Re: get @pwage from user list and send notification e-mail.
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Jake,

What happens if you make $user to be $lstrusername ?

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#68809 - 2002-08-02 06:02 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
Kent,
I've try what you're suggesting and still received the same error.
Code looks like this:
code:
 
;$lstrusername = $user
$userobj = GetObject("WinNT://$LDomain/$user")


Top
#68810 - 2002-08-02 06:13 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
After further testing, Kent's code is functioning using a variable ($user) as the username. I think the error occurs when attempting to split the single user name from the user list, which is created by net users /domain pipe to a text file.
The code to split the username from the list:
code:
 
break on
$nul=open(1,"c:\users.txt")
$line=readline(1)
while not @error
for each $user in split($line)
gosub calculate
next
loop
$line=readline(1)
exit


Top
#68811 - 2002-08-02 07:52 PM Re: get @pwage from user list and send notification e-mail.
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I'm sorry if I'm not up to speed, I'm getting a late start to this thread...but why are we using the piped results of 'net user /domain' when you can do it from ADSI using filters? If I'm correct, this isn't being run from loginscript, but is a service script (correct me if I'm wrong).

If so, then...

code:
$user=getobject("WinNT://@domain")
$user.filter="User",""
for each $user in $user
? $user.name " " $user.PasswordExpirationDate
next

...will enumerate through all of the user accounts on the scpecified domain.

[ 02 August 2002, 20:03: Message edited by: Chris S. ]

Top
#68812 - 2002-08-02 08:37 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
Chris,
All your assumptions are correct and your code did the trick for what I wanted to do. If you were here, I buy you a beer [Razz] . Thanks

Top
#68813 - 2002-08-02 08:39 PM Re: get @pwage from user list and send notification e-mail.
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Send beer to:

Relizon
220 E. Monument Ave.
Dayton, OH 45402
c/o Chris S.

[Wink]

Top
#68814 - 2002-08-02 08:44 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
You drink imports or domestic? All I have is Heineken [Wink]

Here's the code (from Kent & Chris) if somebody have to do something like this.
code:
 
$user=getobject("WinNT://@domain")
$user.filter="User",""
for each $user in $user
? $user.name " " $user.PasswordExpirationDate
$tt = SPLIT($user.PasswordExpirationDate," ")
$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
next


Top
#68815 - 2002-08-02 10:02 PM Re: get @pwage from user list and send notification e-mail.
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
How about this then...

code:
$user=getobject("WinNT://@domain")
$user.filter="User",""
for each $user in $user
? $user.name " "
$maxage = $user.MaxPasswordAge / (60*60*24)
$psdage = $user.PasswordAge / (60*60*24)
Select
Case $maxage < $psdage
"Password is expired."
Case $maxage - $psdage <= 7
"Password will expire in 7 days or less."
Case 1
"Password age within parameters."
Endselect
next

...that should be worth a six-pack at least. Oh, import or domestic is fine. [Wink]

[ 03 August 2002, 00:15: Message edited by: Chris S. ]

Top
#68816 - 2002-08-02 11:09 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
O.K. with the economy these days, if you keep going, I'll have to give you my paycheck [Razz] [Roll Eyes]
Top
#68817 - 2002-08-03 12:54 AM Re: get @pwage from user list and send notification e-mail.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jake, don't give all!
just the part you will get raise for this supernatural code [Big Grin]
_________________________
!

download KiXnet

Top
#68818 - 2002-08-06 01:52 AM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
"supernatural code" I will agree with, but getting a raise might be a "supernatural event" [Frown] . Thanks again for all the help from everyone.
Top
#68819 - 2002-08-14 03:29 PM Re: get @pwage from user list and send notification e-mail.
Tarfin Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
Loc: Jenison, MI USA
Here's a way I do that in VB Script using ADSI. It will even prompt you for the domain name in case you have multiple domains to administer.

code:
 Set FSO = CreateObject("Scripting.FileSystemObject")
Set AFileStream = FSO.CreateTextFile("c:\pwexp.txt", True)

DomainName = InputBox("Enter the domain name in which the user account exists:", "Enter Domain Name")
Set Domain = GetObject("WinNT://" & DomainName)
Domain.Filter = Array("User")
For Each UserAccount In Domain
AFileStream.WriteLine UserAccount.Name &"'s password will expire on " &UserAccount.PasswordExpirationDate
Next
AfileStream.Close


Set WSHShell = WScript.CreateObject("WScript.Shell")
' Get a reference to the Word Application object.
Set appWord = Wscript.CreateObject("Word.Application")
appWord.Visible = TRUE
appWord.Documents.Open("C:\pwexp.txt")

Edit: Didn't address the emailing issue but this wins half the battle. =D

[ 14. August 2002, 15:33: Message edited by: Tarfin ]

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.062 seconds in which 0.024 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