Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Please asist me to ajust my object life cycle script

$
0
0

Below is the script that I run every month to disable stale users.

The results returned will include all users and computers in the lockdown OU.

I wish to exclude the lockdown OU from the results.

Please can you assist.

My script.

On Error Resume Next

'Scriptname:  ObjectLifeCycle.vbs
'Author: 
'Version: 
'Description: 


Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim WshShell, fso, objRootDSE, strDomain, strTmpPath

Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")


' **************** Customisable Settings *****************
'The WeeksInactive value is used on USER objects to determine when last a logon event look place.  Anything beyond this value will be deemed an inactive account.
WeeksInactive = 4 

'The DaysInactive value is used to on COMPUTER objects to indentify stale computer objects
DaysInactive = 60
'*********************************************************

If wscript.Arguments.Count <> 1 Then
 Wscript.echo "Usage:  cscript ObjectLifeCycle.vbs <OutputFileName>"
 Wscript.quit
End if

'Open Output file
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Wscript.Arguments.Item(0), ForAppending, True)
f.WriteLine "*****Users inactive for more than " & WeeksInactive & " weeks."
f.Write CheckUsers
f.WriteLine
f.WriteLine "*****Computers inactive for more than " & DaysInactive & " days."
f.Write CheckComputers
f.close

Function CheckUsers()
 Set oExec = WshShell.Exec("dsquery.exe user " & strDomain & " -inactive " & WeeksInactive)
 Do While oExec.Status = 0
  strIn = oExec.StdOut.Readall
  iLen = len(strIn)
  WScript.Sleep(100)
  If len(strIn) = iLen then 'Output is finished
   CheckUsers = strIn
   Exit do
  End if
 Loop
End Function


Function CheckComputers()
 Set oExec = WshShell.exec("dsquery.exe computer " & strDomain & " -stalepwd " & DaysInactive)
 Do While oExec.Status = 0
  strIn = oExec.StdOut.Readall
  iLen = len(strIn)
  WScript.Sleep(100)
  If len(strIn) = iLen then 'Output is finished
   CheckComputers = strIn
   Exit do
  End if
 Loop
End Function


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>