Page 1 of 1 1
Topic Options
#36265 - 2003-02-11 09:04 AM Password never expires
Mike Duhwald Offline
Fresh Scripter

Registered: 2003-01-13
Posts: 40
Hello,
I want do modify multiple useraccounts in the active directory (set the flag 'password never expires'). If possible the script should get the names of the account out of an text- or excelfile:

test1;0
test2;1
.
.

The numbers behind the username should indicate the status of the changes (0 - remove flag, 1 - set the flag)

Can anybody help me?

Regards
Mike

Top
#36266 - 2003-02-11 02:24 PM Re: Password never expires
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here's a script that checks for that flag. With some modification it should fit your needs.

code:
break on cls

;ADS UserFlags Typedef
$ADS_UF_SCRIPT = &1
$ADS_UF_ACCOUNTDISABLE = &2
$ADS_UF_HOMEDIR_REQUIRED = &3
$ADS_UF_LOCKOUT = &10
$ADS_UF_PASSWD_NOTREQD = &20
$ADS_UF_PASSWD_CANT_CHANGE = &40
$ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = &80
$ADS_UF_TEMP_DUPLICATE_ACCOUNT = &100
$ADS_UF_NORMAL_ACCOUNT = &200
$ADS_UF_INTERDOMAIN_TRUST_ACCOUNT = &800
$ADS_UF_WORKSTATION_TRUST_ACCOUNT = &1000
$ADS_UF_SERVER_TRUST_ACCOUNT = &2000
$ADS_UF_DONTEXPIREPASSWD = &10000
$ADS_UF_MNS_LOGON_ACCOUNT = &20000
$ADS_UF_SMARTCARD_REQUIRED = &40000
$ADS_UF_TRUSTED_FOR_DELEGATION = &80000
$ADS_UF_NOT_DELEGATED = &100000

$nul=redirectoutput(@scriptdir+"expiredaccounts.txt",1)
$user=getobject("WinNT://@domain")
$user.filter="User",""
for each $u in $user
$objUser=getobject("WinNT://@domain/"+$u.name)
$MaxAge=$objUser.MaxPasswordAge/86400
$PsdAge=$objUser.PasswordAge/86400
if $MaxAge <= $PsdAge
$UserFlags = $objUser.Get("UserFlags")
if AllFlags($UserFlags, $ADS_UF_DONTEXPIREPASSWD)=0 or AllFlags($UserFlags, $ADS_UF_ACCOUNTDISABLE)=0
? $objUser.name " " $maxage - $psdage " " $objUser.LastLogin
endif
endif
next

FUNCTION AllFlags($iNum, $iTst)
$iNum=Val($iNum) $iTst=Val($iTst)
IF $iTst=0 $AllFlags=0 EXIT ENDIF
$AllFlags=(($iNum & $iTst)=$iTst)
ENDFUNCTION


Top
#36267 - 2003-02-12 03:57 AM Re: Password never expires
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And take a look at User Manager Script
_________________________
There are two types of vessels, submarines and targets.

Top
#36268 - 2003-08-12 07:30 PM Re: Password never expires
Scrib Offline
Fresh Scripter

Registered: 2002-07-08
Posts: 13
Loc: uk
Hi,
I have the same problem.

I can create a local user account using the "Net Users" NT command on an NT domain. However there is no way of setting the password to "Never Expire" by this method (thanks MS!).

I've had a play with the script below and I have got totally lost. I've found a microsoft article on how to do this using vbs (see http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/user/scrug115.asp)but I need to do it in KIX.

Can anyone guide me into coding this in kix??

Top
#36269 - 2003-08-13 12:17 AM Re: Password never expires
Chris S. Offline
MM club member
*****

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



Break On

$ADS_UF_DONT_EXPIRE_PASSWD = &10000

$strDomainOrWorkgroup = @DOMAIN
$strComputer = @WKSTA
$strUser = "Jenny"

$objUser = GetObject("WinNT://" + $strDomainOrWorkgroup + "/" +
    $strComputer + "/" + $strUser + ",User")
$objUserFlags = $objUser.Get("UserFlags")
If ($objUserFlags & $ADS_UF_DONT_EXPIRE_PASSWD) = 0
    $objPasswordExpirationFlag = $objUserFlags + $ADS_UF_DONT_EXPIRE_PASSWD
    $objUser.Put ("userFlags"$objPasswordExpirationFlag)
    $objUser.SetInfo
    @SERROR ?
Else
    "Account already has the Password Never Expires Flag." ?
EndIf


Top
#36270 - 2003-08-14 12:13 AM Re: Password never expires
Scrib Offline
Fresh Scripter

Registered: 2002-07-08
Posts: 13
Loc: uk
Thats works a treat!!!

Thanks!!

Top
#203875 - 2011-11-29 03:46 PM Re: Password never expires [Re: Chris S.]
cividan Offline
Fresh Scripter

Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
I just want to say thanks as I used your code with some minor change to check for the password never expire flag for user on my domain.

 Originally Posted By: Chris S.
How about...
 Code:
Break On

$expire = (@MAXPWAGE - @PWAGE - 1)
$ADS_UF_DONT_EXPIRE_PASSWD = &10000

$strDomainOrWorkgroup=@DOMAIN
$strUser=@userid
$objUser=GetObject("WinNT://" + $strDomainOrWorkgroup + "/" + $strUser + ",User")
$objUserFlags=$objUser.Get("UserFlags")
If $expire < 3 & ($objUserFlags & $ADS_UF_DONT_EXPIRE_PASSWD) = 0
    ? "You should change your password now as it expire in less than 3 days."
    Shell "%systemroot%\system32\CMD.EXE /C pause"
Else
    ? "Account has the Password Never Expires Flag. or expire in more than 3 days" 
EndIf

Top
#203876 - 2011-11-29 04:10 PM Re: Password never expires [Re: cividan]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
LOL \:o
8 years between the posts. Now nobody can say that we do not recycle

Great to see that the "oldies" are still useful every now and then.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#203877 - 2011-11-30 01:10 AM Re: Password never expires [Re: Mart]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
nice.
_________________________
!

download KiXnet

Top
#203878 - 2011-11-30 05:03 PM Re: Password never expires [Re: Lonkero]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Interesting that cividan would choose to shell out to CMD to pause rather than do it in KIX.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#203879 - 2011-11-30 05:19 PM Re: Password never expires [Re: Les]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol. didn't even see that.
_________________________
!

download KiXnet

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 1013 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.077 seconds in which 0.038 seconds were spent on a total of 13 queries. Zlib compression enabled.

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