• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 836
  • 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!
1 Solution
Have you tried searching the Microsoft script center?


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.
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

Open in new window

changjiaAuthor Commented:

You are awesome!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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