
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2009 09:28 PM
This Script must be run under an account with the correct rights on the DB. There is no error trapping nor validation in the script.
Here's the code:
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
- Labels:
-
Custom Actions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2010 05:04 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2009 09:18 PM
objCommand.CommandText = "SELECT Name FROM 'LDAP://dc=services,dc=local' WHERE objectCategory='computer' AND Name='" & SQLName & "'"
set objRSAD = objCommand.Execute
My domian is Services.local
Do i have that setup correctly?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2009 11:29 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2009 03:59 PM
Is it possible to do something similar for Useraccounts?
We have a lot of old Useraccounts stored in the database.
(users that are no longer working for our company)
These accounts do not exist any more in our AD.
Thank you!
Greetings,
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2009 02:49 AM
SELECT Name FROM 'LDAP://dc=Microsoft,dc=com' WHERE
or
SELECT Name FROM 'LDAP://dc=Cox,dc=net' WHERE
or
SELECT Name FROM 'LDAP://dc=PETA,dc=org' WHERE

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2009 02:25 AM
I am getting the following Script Error:
Script: C:\LSShare\CleanLansweeper.vbs
Line: 43
Char: 5
Error: Table does not exist
Code: 80040E37
Source: Provider
I think my problems are the following:
' ******************************************************************
' * 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
I am not sure what is ment by "Replace COMPANY, COM by your DOMAIN"
Would it be:
"SELECT Name FROM 'LDAP://dc=MYCompanyName,dc=MYDomainName' WHERE
Help!!!


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2009 03:23 PM
"Error: Resource has been moved or is unavailable. Please contact the forum admin."

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2009 07:52 PM
I tested this out, and indeed it works.
But only on the domain where you are running it.
It deletes all the computers that are on a different domain.
I'm sure a line could be changed to make sure it doesn't delete the other computers, but I have yet had the time to look at it.
If/when I find it, I will post it here. Unless someone changes it before me.
Regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2009 03:37 PM
