ekingg 2008-4-8 10:20
求个脚本,列出90天AD里没登录的用户.
求个脚本,列出90天AD里没登录的用户,并删除.*L{6N-OT
DF
1dKj`%Y/T o
顺便问下有什么可以加密VBS的内容的工具或算法.&f4u)Q4`%pzqiL
h
T4L!j$boTi
[[i] 本帖最后由 ekingg 于 2008-4-8 11:06 编辑 [/i]]
ekingg 2008-4-8 17:00
高手今天都很忙吗
8Em S"F
U
偶把现在查找的脚本放上来给大家看看. :P
G([IC\]
Vk/J'R.Tx,~G
'Modified for US Date format m/d/y, file name ? still a problem_r~#qsN
I
'Modified for disabled new account Notlogon and disabled >= 90 days3Xv+H5W
h oo%L)MK W4}
'Modified for new account not logon >= 30 days and not disabledF9ya rpb-RW8|,a&t
!BH9Y9i#[dO2GhT
'ODD Users: disabled but not listed, sovled by using "m/d/y" format for condition^3L2s$dIVr0e
iko.|w
V.l+f6m8TB v
'********************
B{ G3b@j9x
'* Define Constants **c^$Br%p(dX9Z5A
'********************
?`0~wA
Const MgmtDel = -90 'disabled or not logon for XX days, old account!
!?5qx!HrJ-d,I/A:sN
Const MgmtDis = -30 'not logon for XX days, new account!Vk7hdkm
Const ADS_PROPERTY_APPEND = 3
H'g4NT,Sp(bc
Const ADS_NAME_TYPE_NT4 = 3
9E_$p[2h{6@j2sTS
Const ADS_NAME_TYPE_1779 = 1
Y|1NRRBZ
A
}^H1T!Bp
'*********************
@)tw!^
z)d
k U
'* Declare Variables *
V+w O`9n_
'*********************j0ig)I2fii|
Dim expDate 'expiration date4uF:[:@w6U4Rg&M
Dim createDate 'account first created
Wb j3D;h@0f k
Dim lastLogDate 'account last logon dateG%CZ`'a
Dim lastmodDate 'last modified date
6DS!y5@W
Dim accDisabled 'if account disabled, 514 for disable, 512 for enable(e
e
PN*{o$D
Dim mFile
$J-V
H&Y,Uw
Dim WshShell
[)N
}4QJ#jY
L
Dim strFilter.R&T7O}1D\Om6J~
Dim strAttributes
8I)T'c0r
]5w9c
Dim strQuery
9J,d,]ZOx6i
Dim objRootDSE
5r(k.znJ:V
Dim strDNSDomain;@-S9W |%O;D
Dim objCommand4gW;r(\{B|o5?
Dim objConnection
j!Sm-P:n7~%JO
?
Dim MyArr
Mr*[1Q(z9mf
Dim Upper
-V*g$W7}:wS
Dim strUserNTName
h\3C8yN
Dim objTrans
&?+Yk8sfg
{x
Dim strNetBiOSDomain
u9V9RNG$A-iYh
Dim strUserDNZd-W3n%u)g2R
Dim objDate|2im!{
wv
B`,|u!O Owd:V
'*********************yOjEWTm N)L!l
'* Get Required Info *(T,Kv|6f/K3\%g%T
@:qOF
'* and Build Outputs *
-K;a+X F_Rf
'*********************
?q%w \ ~T
' Determine DNS domain name.tj_{l~"}
Set objRootDSE = GetObject("LDAP://RootDSE")
3hy
ld[L#H
strDNSDomain = objRootDSE.Get("defaultNamingContext") 'domain DNS name
(\%E1Zo.\4a
strNetBiOSDomain = "ASIA_RRD_COM" 'domain NetBIOS name0RxDld;HZ)^
Set fso = CreateObject("Scripting.FileSystemObject")7t4N!G|y#fMDH_%B
Set mFile = fso.CreateTextFile("./" & strNetBiOSDomain & "-UserManage-" & Year(Date) & "-" & Month(Date) & "-" & Day(Date) & ".txt") 5yL:~'K]Aic
mFile.Writeline("UserName,AccountType,SinceCreated,SinceLastModified,SinceLastLogon,Actions")
\jT&b3t9G_.J
'******************
#]Q0Y5s1`X s8RU|
'* Search the Domain * SHOULD USE ADO LDAP to support timestamp attr
&D W\)M+_"qn:r"Q
'******************
d9\F.^*N
' Use ADO to search Active Directory.
8i:kr3R,q:w
J6K5T
Set objCommand = CreateObject("ADODB.Command")o|f1G-h^8M6}
Set objConnection = CreateObject("ADODB.Connection")Kr$j!Yd)x5D/d
objConnection.Provider = "ADsDSOObject"
#wa IE+V
objConnection.Open "Active Directory Provider"~2x!JvYt
i
objCommand.ActiveConnection = objConnection6AG1b
E8ES
strBase = "<LDAP://" & strDNSDomain & ">"
/|\$E2q$l-z
strFilter = "(&(objectCategory=person)(objectClass=user))"
4p(U;?C ~
strAttributes = "givenName,sn,sAMAccountName,name,displayName,userPrincipalName,whenCreated,lastLogon,whenChanged,userAccountControl"
"D'f5x!g9m4O.H3gbQ
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"]U'DY}d)y
objCommand.CommandText = strQueryT5{1WaY){ x:}
C;I
objCommand.Properties("Page Size") = 20
6y$M/y:|(L
_r
objCommand.Properties("Timeout") = 30
0}C0XiY#PH;rm+E
objCommand.Properties("Cache Results") = False8r8_&A5V0U6up"x_
objCommand.Properties("Sort On") = "sAMAccountName"
%Y%ZBk&Y@+h6^3B
yh
Set objRecordSet = objCommand.Executeq1[jK
{9b
Set objRecordSetArr = objCommand.Execute!HS{K5Y.J^
w@
d~3q
If objRecordSet.EOF Then
GVk`!r1l}f
Wscript.Echo "No user found!!".hM+i y[:kDlqH
End If
:yWJX3AD
7a_O7RK
'if user exists, then run search
!m5_uz1kt4JC7r
'****************************
)foT&Gi;Le|
'* Start Loop to find Users *9h9w"M])[z
'*****************************V4eq1A${ h#c\2X
Do Until objRecordSet.EOF
@*v$x;cE'u[}(}.J,W
_!_qB:X)s
strUserNTName = objRecordSet.Fields("sAMAccountName").Value
!I$TC;g_
J5}i6{-cH/C|
'Wscript.echo strUserNTName(l{!G j}h;Y)L
q
Set objTrans = CreateObject("NameTranslate")
:c$u~-Yp&H/]&t&mqv
objTrans.Set ADS_NAME_TYPE_NT4, strNetBiOSDomain & "\" & strUserNTName+c"r:X
P7d B
\A'Y6E/{9d,Bj
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
.}vQ1|2|W
+~%tD'?pQ S~[i
' Bind to the user object in Active Directory with the LDAP provider.+\T!Qt^ U-\
'On Error Resume Nextg
`"b-g[s)X
If InStr(strUserDN,"SystemMailbox") = False Then $f;N%F@ J
'MsgBox "bingo!"
2o_k6Qxm
Set objUser = GetObject("LDAP://" & strUserDN)cY$g7j
s3nhd Yg
objUserNULL = 0 'False for non-exchange systemMailbox account5S"|/Y9oKu
ElseY/\O.Nk9\
objUserNULL = 1 'true for exchange systemMailbox account
WvW^2{:z1B |0C
End if
C-X,i La0R*M
:d9Z^"H
g$n t
'Reset counter values