Home > 3rd Party Tools > Web Remote Console v3.21 Delete from AD

Web Remote Console v3.21 Delete from AD


Here is yet another button for Ron Crumbaker’s Web Remote Console v3.21.  This script deletes the device from AD but does not allow deletion of objects with Windows Server in the Operating System attribute.

‘———————————————————————————-
‘This button will remove the device from AD.
‘———————————————————————————-
Sub Btnl32_OnClick
    on error resume Next
    Dim CompName, intrespond, intInput
    CompName = trim(document.frmMain.txtValue.value)
    IF len(trim(CompName)) = 0 THEN
        msgbox “Please type a Machine Name.”,,”Uninstall SCCM Client”
    Else
        ExecuteSearch = SearchDistinguishedName(CompName)
    END IF
End SUB

‘———————————————————————————-
‘Searches for a distinguished name for AD deletion
‘———————————————————————————-
Public Function SearchDistinguishedName(ByVal vSAN)
    Const ADS_SCOPE_SUBTREE = 2
    Dim oRootDSE, oConnection, oCommand, oRecordSet, intrespond, strOS, strCurDom, objComputer, strLocation, strNotinAD
    Set oRootDSE = GetObject(“LDAP://rootDSE”)
    Set oConnection = CreateObject(“ADODB.Connection”)
    oConnection.Open “Provider=ADsDSOObject;”
    Set objCommand = CreateObject(“ADODB.Command”)
    objCommand.ActiveConnection = oConnection
    strCurDom = “‘LDAP://” & oRootDSE.get(“defaultNamingContext”) & “‘”    intRespond = MsgBox(“The current domain set is: ” & strCurDom & ” is this same domain as the device you wish to delete?  Please note that this can take up to 1 minute.”, vbYesNo + vbQuestion + vbSystemModal, “Domain”)
        If intrespond = vbYes Then
            ldstring = “‘LDAP://” & oRootDSE.get(“defaultNamingContext”) & “‘”
        ELSE
            IF intrespond = vbNo THEN
                intInput = msgbox(“Please log into the console on a device in the appropriate domain to accomplish this.”, vbInformation + vbSystemModal, “Domain”)
            END IF
        END IF    objCommand.CommandText = “Select Name, distinguishedName, operatingSystem from “& ldstring & ” where objectClass=’computer'”     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
        IF lcase(objRecordSet.Fields(“Name”).Value) = lcase(vSan) THEN
            strOS = objRecordSet.Fields(“operatingSystem”).Value
            IF Instr(ucase(strOS), UCase(“Server”)) THEN   
                intrespond = msgbox (“Deletion of server objects from AD is not allowed via this console.”, vbInformation + vbSystemModal, “Domain”)
                strNotinAD = “No”
                Exit Do
            ELSE
                intrespond  = msgbox (“Are you sure you want to delete this device from AD?” & vbCrLf _
                & “Computer Name: ” & objRecordSet.Fields(“Name”).Value & vbCrLf _
                & “Location: ” & objRecordSet.Fields(“distinguishedName”).Value  & vbCrLf _
                & “Operating System: ” & objRecordSet.Fields(“operatingSystem”).Value, vbYesNo + vbQuestion + vbSystemModal, “Domain”)
                strLocation = chr(34) & “LDAP://” & objRecordSet.Fields(“distinguishedName”).Value & chr(34)
                ‘intrespond   = msgbox (strLocation, vbInformation + vbSystemModal, “Domain”)
                IF intrespond = vbYes THEN
                    Set objComputer = GetObject(“LDAP://” & objRecordSet.Fields(“distinguishedName”).Value)
                    ‘objComputer.Delete (0)
                    objComputer.DeleteObject(0)
                    intrespond   = msgbox (“Computer Name: ” & objRecordSet.Fields(“Name”).Value & ” has been deleted from ” & strLocation, vbInformation + vbSystemModal, “Domain”)
                    strNotinAD = “No”
                    Exit Do
                ELSE
                    intrespond   = msgbox (“The device HAS NOT been deleted from AD.”, vbInformation + vbSystemModal, “Domain”)
                    strNotinAD = “No”
                    Exit Do
                END IF
            END IF
        ELSE
            strNotinAD = “Yes”
        END IF
        objRecordSet.MoveNext
    Loop
    If strNotinAD = “Yes” THEN
        intrespond   = msgbox (“The device was not found in AD.  Please verify the name.”, vbInformation + vbSystemModal, “Domain”)
    END IF
End Function

Advertisements
Categories: 3rd Party Tools
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: