Login | |
|
 |
RE: Vbscript equivilent to dsquery? - inactive switch q... - 6/20/2008 1:39:42 AM
|
|
 |
|
| |
dm_4ever
Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
Maybe try the lastlogontimestamp or pwdlastset and see if it returns the same machines dsquery returns. I believe that the only way to get accurate info using a query is to query all DC's, get the latest date/time for each machine, and then do your comparision....or you could run you dsquery and then query those machines to see if they are disabled.
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Vbscript equivilent to dsquery? - inactive switch q... - 6/20/2008 5:29:27 AM
|
|
 |
|
| |
Stumpedtechy
Posts: 41
Score: 0
Joined: 11/30/2007
Status: offline
|
Okay I have this and it should work but its not in one spot - ' ************************************************************************ ' ************************************************************************ ' *** *** ' *** This script is to be used to check all currently enabled *** ' *** computer accounts in the designated OU and its SubOUs for *** ' *** old/inactive computer accounts. *** ' *** It will check the accounts last active date vrs the date the *** ' *** the script is ran and if the difference is over the specified *** ' *** number of weeks it will first ping the computer and then, if *** ' *** the ping does not reply, the script will then perform the *** ' *** following steps - *** ' *** *** ' *** - Put a description in the computer account indicating, *** ' *** Number of weeks inactive, *** ' *** Time and date of script run, *** ' *** Where the machines LDAP location was before it was moved. *** ' *** - Disable the computer account. *** ' *** - Move the computer account from the OU it is in to the *** ' *** designated disabled computer accounts OU. *** ' *** *** ' *** *** ' *** Lines to be modified - *** ' *** strWeeks = Change this to be the number of weeks not active *** ' *** on the domain. Do not make this too short as *** ' *** traveling users might not use their machines on the *** ' *** domain for a few weeks at a time. *** ' *** strMainLDAP = LDAP location of the OU and SubOUs you want to *** ' *** scan for old inactive machine accounts. *** ' *** strDisableLDAP = Dump location you want the disabled accounts *** ' *** to go into once disabled. *** ' *** *** ' *** WARNINGS-WARNINGS-WARNINGS-WARNINGS-WARNINGS-WARNINGS-WARNINGS *** ' *** 1) This script does not make any LDAP locations. They have to *** ' *** already exist. *** ' *** 2) This script will overwrite existing computer descriptions. *** ' *** *** ' *** *** ' *** Authored by: Eric Theisen *** ' *** Date: February 21, 2008 *** ' ************************************************************************ ' ************************************************************************ strDate = Replace(Date,"/","-") strTime = Replace(Time,":","-") strWeeks = "29" strMainLDAP = "LDAP://OU=Computer,DC=DOMAIN,DC=COM" strDisableLDAP = "LDAP://OU=Disabled Computers,DC=Domain,DC=Com" Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCOmmand.ActiveConnection = objConnection objCommand.CommandText = _ "Select Name, ADsPath from '"&strMainLDAP&"' WHERE objectClass='computer' " & _ "AND userAccountControl='4096'" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF strADsPath = objRecordSet.Fields("ADsPath").Value strDeviceName = objRecordSet.Fields("Name").Value Set objChange = GetObject(strADsPath) Set objLastLogon = objChange.Get("lastLogonTimestamp") intLastLogonTime = objLastLogon.HighPart * (2^32) _ + objLastLogon.LowPart intLastLogonTime = intLastLogonTime / (60 * 10000000) intLastLogonTime = intLastLogonTime / 1440 StrTime = intLastLogonTime + #1/1/1601# dtmEndingDate = strTime intWeeks = DateDiff("WW",dtmEndingDate,now) wscript.echo intWeeks wscript.echo strWeeks If intWeeks > strWeeks then If IsAlive(strDeviceName) = False then objChange.Put "description" , "Machine over "&strWeeks&" weeks inactive. Disabled "&strDate&" @ "&strTime&" by script. Moved from"&strADsPath&"." objChange.Put "userAccountControl", "4098" objChange.SetInfo Set objOU = GetObject(""&strDisableLDAP&"") objOU.MoveHere strADsPath, vbNullString End if End If objRecordSet.MoveNext Loop MsgBox "Execution completed successfully." , vbInformation, "Execution completed" Function IsAlive(strDeviceName) '---------- Test to see if host or url alive through ping ----------------- ' Returns True if Host responds to ping ' ' Though there are other ways to ping a computer, Win2K, ' XP and different versions of PING return different error ' codes. So the only reliable way to see if the ping ' was sucessful is to read the output of the ping ' command and look for "TTL=" ' ' strRComputer is a hostname or IP Const OpenAsASCII = 0 Const FailIfNotExist = 0 Const ForReading = 1 Dim objShell, objFSO, sTempFile, fFile Set objShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName objShell.Run "%comspec% /c ping.exe -n 2 -w 500 " & strDeviceName & " >" & sTempFile, 0 , True Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII) Select Case InStr(fFile.ReadAll, "TTL=") Case 0 IsAlive = False Case Else IsAlive = True End Select ffile.close objFSO.DeleteFile(sTempFile) Set objFSO = Nothing Set objShell = Nothing End Function It is failing at - intWeeks = DateDiff("WW",dtmEndingDate,now) wscript.echo intWeeks wscript.echo strWeeks If intWeeks > strWeeks then intWeeks is giving me back 26 as the number. But if I change strWeeks to 20 or 29 it does not run. just as a test I remmed out intWeeks = DateDiff("WW",dtmEndingDate,now) and I put in intWeeks = "26" and it works just fine. Could it be something wrong with how intWeeks is giving me back the number 26?
|
|
| |
|
|
|
 |
RE: Vbscript equivilent to dsquery? - inactive switch q... - 6/20/2008 7:43:14 AM
|
|
 |
|
| |
dm_4ever
Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
What if you made strWeeks = 26 ' or 29 or any number without the quotes; with the quotes you're defining it as a string Maybe to make sure you're comparing numerical values If CInt(intWeeks) > CInt(strWeeks) then
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|