vbscript to check accounts that have been inactive for 90 days or more

Hi Experts:
I need a vbscript that can check accounts that have been inactive for 90 days or more on a local server.
The server is not a member of any domain.

Could anyone help me with this ?

Thanks

changjiaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 server.  Running it will echo the names of any local users who haven't logged in within 90 days.


On Error Resume Next
 
strComputer = "servername"
intDays = 90
 
Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")
 
For Each objUser In colAccounts
    If DateDiff("d", objUser.LastLogin, Now) >= intDays Then
        WScript.Echo objUser.Name
    End If
Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rejoinderCommented:
This should work for you.
On Error Resume Next
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
wscript.echo strComputer
Set colUsers = GetObject("WinNT://" & strComputer)
colUsers.Filter = Array("user")
For Each objUser in colUsers
    strADSPath   = "WinNT://" & strComputer & "/" & objUser.Name & ",user"
    Set objVar   = GetObject(strADSPath)
    strLastLogin = objVar.LastLogin
    if err.number <> 0 then
        strLastLogin = "Not on record"
        err.clear
    end if
    if IsDate(strLastLogin) then
        if DateDiff("d",strLastLogin,Date) > 90 then
            wscript.echo vbTab & objUser.Name & vbTab & strLastLogin
        end if
    else
        wscript.echo vbTab & objUser.Name & vbTab & strLastLogin
    end if
Next

Open in new window

0
changjiaAuthor Commented:
Thanks for the help!
Shift-3,I tried your script but nothing happens.
Rejoinder, your script creates pop windows, is there a way to put them in a text file instead of creating pop ups?

Thanks
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

changjiaAuthor Commented:
Hi Shift-3, Sorry that I put the wrong computer name, your script works great now. but Could you modify the script so it creates a txt file instead of pop ups?

Thanks
0
Shift-3Commented:
So revised.


Const ForWriting = 2
 
strComputer = "servername"
intDays = 90
strLog = "log.txt"
 
On Error Resume Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.OpenTextFile(strLog, ForWriting, True)
 
Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")
 
For Each objUser In colAccounts
    If DateDiff("d", objUser.LastLogin, Now) >= intDays Then
        objLog.WriteLine objUser.Name
    End If
Next
 
objLog.Close

Open in new window

0
rejoinderCommented:
OK - this will output the results to a file.
On Error Resume Next
 
strFile     = "Accounts-Over-90-Days.txt"
Set objFSO  = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, 2, True)
 
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
objFile.WriteLine strComputer
Set colUsers = GetObject("WinNT://" & strComputer)
colUsers.Filter = Array("user")
For Each objUser in colUsers
    strADSPath   = "WinNT://" & strComputer & "/" & objUser.Name & ",user"
    Set objVar   = GetObject(strADSPath)
    strLastLogin = objVar.LastLogin
    if err.number <> 0 then
        strLastLogin = "Not on record"
        err.clear
    end if
    if IsDate(strLastLogin) then
        if DateDiff("d",strLastLogin,Date) > 90 then
            objFile.WriteLine vbTab & objUser.Name & vbTab & strLastLogin
        end if
    else
        objFile.WriteLine vbTab & objUser.Name & vbTab & strLastLogin
    end if
Next

Open in new window

0
changjiaAuthor Commented:
You two are awesome!! Great Thanks to both of you.
I have to give Shift-3 a little more points because he responded faster.
But both of you are really GREAT!!
0
Hobbs13Commented:
Ok, how does this script work?

I ran the script from one of my Domain Controllers (We have 2 total) and replaced strComputer with one of my DC Names. According to this script 1/3rd of of my users have not logged in over last 90 days. This is not possible so I figure I am doing something wrong. Any thoughts?

0
Shift-3Commented:
This script only checks the activity of local users.  It won't work for domain users.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

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.