‎01-29-2009 09:28 PM
Dim objCNSQL
Dim strSQLDELETE
Dim strSQLQUERY
Dim objRSSQL
Dim SQLName
Const ADS_SCOPE_SUBTREE = 2
strSQLQUERY="select * from tblcomputers"
' **************** AD Connection ****************************
'
Set objCNAD = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objCNAD.Provider = "ADsDSOObject"
objCNAD.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objCNAD
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
' **************** LAnsweeper connection ****************************
' * Replace SERVERNAME by your SQL Server Instance
'
Set objCNSQL=CreateObject("ADODB.Connection")
objCNSQL.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Integrated Security=SSPI;Server=SERVERNAME\sqlexpress;Database=Lansweeper32"
' **************** REading Lansweeper ****************************
'
set objRSSQL=objCNSQL.execute(strSQLQUERY)
' ******************************************************************
' * For each record in tblcomputers
' * If computername exist in AD, do noting
' * Else, delete the record in the DB
' *
' * REplace COMPANY, COM by your DOMAIN
'
objRSSQL.MoveFirst
Do Until objRSSQL.EOF
SQLName=objRSSQL("Computername")
objCommand.CommandText = "SELECT Name FROM 'LDAP://dc=COMPANY,dc=COM' WHERE objectCategory='computer' AND Name='" & SQLName & "'"
Set objRSAD = objCommand.Execute
On Error Resume Next
objRSAD.MoveFirst
if(err.number<>0) then
Wscript.Echo "DELETING: " & SQLName
strSQLDELETE="Delete from tblcomputers where ComputerName='" & SQLName & "'"
objCNSQL.execute(strSQLDELETE)
else
Wscript.Echo "Keep: " & SQLName
end if
objRSSQL.MoveNext
Loop
objCNSQL.Close
‎04-22-2010 05:04 AM
‎12-02-2009 09:18 PM
‎07-13-2009 11:29 PM
‎07-13-2009 03:59 PM
‎06-27-2009 02:49 AM
‎06-27-2009 02:25 AM
Script: C:\LSShare\CleanLansweeper.vbs
Line: 43
Char: 5
Error: Table does not exist
Code: 80040E37
Source: Provider
' ******************************************************************
' * For each record in tblcomputers
' * If computername exist in AD, do noting
' * Else, delete the record in the DB
' *
' * REplace COMPANY, COM by your DOMAIN
'
objRSSQL.MoveFirst
Do Until objRSSQL.EOF
SQLName=objRSSQL("Computername")
objCommand.CommandText = "SELECT Name FROM 'LDAP://dc=COMPANY,dc=COM' WHERE
‎03-13-2009 03:23 PM
‎03-11-2009 07:52 PM
‎02-19-2009 03:37 PM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now