• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 833
  • Last Modified:

VBscript to create a txt file that shows disabled/locked user accounts

Hi Experts:
I am in need a VBscript to create a txt file that shows me all disabled/locked user accounts. The server is not a member of domain.
Thanks in advance for your help!
0
changjia
Asked:
changjia
1 Solution
 
killamankazeCommented:
Have you tried searching the Microsoft script center?

http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true

you will find the source code for the script you are looking for but you may need to modify it depending upon your custom requirements.
0
 
Shift-3Commented:
Paste the script below into a text file with a .vbs extension.  Customize the value of the strComputer variable with the name of the target computer.  Running it will write results to a text file.


Const ForWriting = 2
 
strComputer = "servername"
strLog = "log.txt"
 
On Error Resume Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.OpenTextFile(strLog, ForWriting, True)
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE LocalAccount = 'True'")
 
For Each objUser In colItems
    If objUser.Disabled Then
        objLog.WriteLine objUser.Name & ",disabled"
    ElseIf objUser.Lockout Then
        objLog.WriteLine objUser.Name & ",locked out"
    End If
Next
 
objLog.Close

Open in new window

0
 
changjiaAuthor Commented:
Shift-3:

You are awesome!!!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now