需要VBScript列出已禁用的帐户
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了需要VBScript列出已禁用的帐户相关的知识,希望对你有一定的参考价值。
以下脚本检查本地计算机是否处于非活动状态(90天或更长时间)帐户并禁用它们。该脚本工作正常,但每次执行时都会列出所有已禁用的帐户。我只需要它列出当天被执行时被禁用的帐户。
Option Explicit
Dim objNetwork, strComputer, objComputer, objUser, dtmLast, objGroup, ObjGroupDict
Dim FSO, OutPutFile
Set FSO = CreateObject("Scripting.FileSystemObject")
'1 = reading, 2 = writing, and 8 = appending. The third parameter is a
'boolean true means a new file can be created if it doesn't exist. False
'means a new file cannot be created.
Set OutPutFile = FSO.OpenTextFile("C:TestResult.log", 8, True)
'Bind to the local computer.
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("WinNT://" & strComputer & ",computer")
'Enumerate all users.
objComputer.Filter = Array("user")
For Each objUser In objComputer
Set ObjGroupDict = CreateMemberOfObject(objUser)
If ((Left(objUser.Name,3) <> "au_") And (CBool(ObjGroupDict.Exists("Administrators") = False))) Then
'Trap error if user never logged in.
On Error Resume Next
dtmLast = objUser.lastLogin
If (Err.Number <> 0) Then
dtmLast = #1/1/1970#
End If
On Error GoTo 0
'Check if last logon was more than 90 days in the past.
If (DateDiff("d", dtmLast, Now()) > 90) Then
'Disable the user.
objUser.AccountDisabled = True
objUser.SetInfo
OutPutFile.WriteLine(Now & " " & strComputer & " " & Wscript.ScriptName & " " & objUser.Name & " " & "Disabled")
'MsgBox objUser.Name
Set FSO = Nothing
End If
End If
Next
Function CreateMemberOfObject(objUser)
'Given a domain name and username, returns a Dictionary
'object of groups to which the user is a member of.
'Inputs: objUser - User Object
Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
CreateMemberOfObject.CompareMode = vbTextCompare
Dim objGroup
For Each objGroup In objUser.Groups
CreateMemberOfObject.Add objGroup.Name, "-"
Next
End Function
答案
您正在禁用上次登录超过90天的所有帐户,即使该帐户已被停用也是如此。添加仅匹配未禁用的帐户的条件,代码将执行您想要的操作:
If DateDiff("d", dtmLast, Now) > 90 And Not objUser.AccountDisabled Then
...
End If
以上是关于需要VBScript列出已禁用的帐户的主要内容,如果未能解决你的问题,请参考以下文章
vbscript 各种自定义代码片段 - 有关详细信息,请参阅注释
付款错误:PayPal 错误:此商家沙盒帐户已禁用 DPRP