cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cheche
Champion Sweeper
Here is a very usefull for me custom action. The script disable computer account in AD and move object computer to a recicling OU. Also delete de computer in lansweeper database and active not-scan state for the computer.

With a few modifications may be usefull for you.

'=======================================================================================
Const DESTOU = "OU=Computers for deleting" 'Destination OU in the computer domain
Const ERR1 = "Use: DisableComputer.vbs <Equipo>" 'Error message
Const ERR2 = "Computer not found, continue ..." 'Error message
Const ERR3 = "Computer not in database" 'Error message
Const CONNECTION = "Provider=SQLOLEDB;server=SQLserver;trusted_connection=yes;database=lansweeper" 'Connection string to lansweeper database

If WScript.Arguments.Length = 0 Then
MsgBox ERR1
WScript.Quit
End If

'Get root domain name
Set objDomain = GetObject("LDAP://rootDse")
stForest = Left(objDomain.Get("ldapServiceName"), InStr(objDomain.Get("ldapServiceName"), ":") - 1)
Set ObjDomain = Nothing

'Searching for computer in the global catalog
stComputer = WScript.Arguments(0)
strQuery = "<GC://" & stForest & ">;(&(objectClass=Computer)(cn=" & stComputer & "));DistinguishedName;subtree"

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "ADSI"

Set objRecordSet = objConnection.Execute(strQuery)
If Not objRecordSet.EOF Then
stDistinguishedName = objRecordSet("DistinguishedName")
stDomain = Mid(stDistinguishedName, InStr(1, stDistinguishedName, "dc", vbTextCompare)) 'building computer domain
stDestOU = "LDAP://" & stForest & "/" & DESTOU & "," & stDomain 'building destination OU
stAdsPath = "LDAP://" & stForest & "/" & stDistinguishedName 'building directory object path
Call ProcessComputerAD(stComputer, stAdsPath, stDestOU) 'domain account process
Call ProcessComputerDB(stComputer) 'database process
Else
R = MsgBox(ERR2 & vbNewLine & ERR4,vbOKCancel + vbQuestion, "Warning!")
If R = vbOK Then
Call ProcessComputerDB(stComputer)
End If
End If
objRecordSet.Close
Set objSR = Nothing
objConnection.Close
Set objConnection = Nothing

'=======================================================================================
Sub ProcessComputerAD(stComputer, stAdsPath, stDestOU)
Set objComputer = GetObject(stAdsPath) 'get computer object
objComputer.AccountDisabled = True 'disabling account
objComputer.SetInfo 'update
Set objComputer = Nothing

Set objDestination = GetObject(stDestOU)
objDestination.MoveHere stAdsPath, vbNullString 'moving to destination OU
Set objDestination = Nothing
End Sub
'=======================================================================================
Sub ProcessComputerDB(stComputer)
Set objDB = CreateObject("ADODB.Connection")
objDB.ConnectionString = CONNECTION
objDB.ConnectionTimeout = 60
objDB.Open

'Disabling computer scanning
stQuery = "Insert into TsysDonotscan (Computername) Values ('" & stComputer & "')"
objDB.Execute stQuery

'if exists the computer in database, delete it
stQuery = "Select * From tblComputers Where Computername = '" & stComputer & "'"
Set objRS = objDB.Execute(stQuery)
If Not objRS.EOF Then
stQuery = "Delete From tblComputers Where Computername = '" & stComputer & "'"
objDB.Execute stQuery
Else
MsgBox ERR3
End If

objRS.Close
Set objRS = Nothing
objDB.Close
Set objDB = Nothing
End Sub
'=======================================================================================
1 REPLY 1
kh-vince
Moderator
Moderator

Hello everyone,
Due to the age of this post, it has been archived. Please feel free to start a new post if you wish to continue to discuss this topic.
Thank you for understanding.

New to Lansweeper?

Try Lansweeper For Free

Experience Lansweeper with your own data.
Sign up now for a 14-day free trial.

Try Now