Jump to content

Recommended Posts

Posted

On error resume next

Dim objADO
Dim objContainer
Dim objChild
Dim User

Wscript.Echo "The output will be written to C:\oldComputers.txt"
set objADO = GetObject("LDAP://ou=workstations,ou=liverpool,dc=contoso,dc=local")
set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile ("C:\oldComputers.txt")
set txtStream = fso.OpenTextFile("C:\oldComputers.txt", 8, True)
txtStream.WriteLine vbCrLf
set objContainer = objADO

For each objChild in objContainer
user = MID(objChild.Name,4)
If DateDiff ("d",objChild.LastLogin, Now) > 180 then txtStream.WriteLine user & " ---> " & DateDiff ("d",objChild.LastLogin, Now)_
& " Days since last login." & vbCrLf
Next

msgbox "Done..."
WshShell.run "C:\oldComputers.txt"

PLEASE MAKE SURE NO WORD WRAPPING IS HAPPENING IN YOUR SCRIPT!!!

To make this script work you will need one thing!

You will need the OU in which your computer accounts are kept.

Edit the string LDAP://

(e.g., 'LDAP://OU=workstations,OU=boston,DC=contoso,DC=com')

The script will be written to the root of the c:\ drive.

*Make sure you are an administrator to run this.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...