‎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
‎02-19-2009 08:14 PM
DGoodwin wrote:
I just looked in a couple of my tables where Computername = what we removed via the tool, and I do not see any reference to the removed in the following tables (tbl_software, tbl_OperatingSystem, tbl_ComputerSystem, tbl_Users). It look as if it does remove all data. Maybe LS can clarify if removing a machine from tbl_computers will strip out that machine from the rest of the tables?
‎02-18-2009 04:26 PM
‎02-16-2009 09:57 PM
‎02-10-2009 09:18 PM
‎02-10-2009 06:39 PM
‎02-03-2009 11:08 PM
‎01-30-2009 07:44 PM
‎01-30-2009 03:45 PM
‎01-30-2009 10:15 AM
‎01-29-2009 11:48 PM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now