MSFN Forum: Searching for Computer Account with ADSI - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Searching for Computer Account with ADSI Rate Topic: -----

#1 User is offline   _WearingPants 

  • Group: Members
  • Posts: 2
  • Joined: 08-November 06

Posted 08 November 2006 - 12:51 AM

Afternoon,

We are using Windows PE in a decommissiong process:

- tech boots to PE via F12 pxe
- vbs script runs that gets Manufacturer, model and Serial number of machine using WMI
- vbs script runs that looks up the serial number to computer name in an SMS 2003 SQL database
- vbs script runs that writes this information to a seperate SQL database for reporting
- vbs script runs that kicks off a gdisk32.exe DOD standard wipedisk

What we would like to do is before the HDD is wiped, delete the machine account from Active Directory for an end-to-end decomm process, with minimal tech involvement. Everything above is wokring fine, apart from the delete from AD bit.

We have code that searches through AD (copied below) but it does not work in PE, it returns an error that the table does not exist (lack of credentials) when it goes to execute the command.

By binding directly to the cmputer object/parent OU in AD we can delete it no worries but the problem is that the AD structure has branches of OU's all over the place and we need to be able to search.

Any ideas?

Rob.

---------------------------------
code
---------------------------------

Dim objRecordSet
Const ADS_SCOPE_SUBTREE = 2
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject;USER ID=" & DOM & "\" & USERNAME & ";Password=" & PASSWORD
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://dc=xxx,dc=xxx,dc=xxx>"
strFilter = "(&(objectClass=computer)" & " (cn=" & StrCOMPUTERNAME & "))"
strAttributes = "cn,distinguishedname"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
StrNTName = objRecordSet.Fields("cn")
If StrNTName = StrCOMPUTERNAME Then
DN = objRecordSet.Fields("distinguishedname")
End If
objRecordSet.MoveNext
Loop
objConnection.Close
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing


#2 User is offline   mats 

  • Member
  • PipPip
  • Group: Members
  • Posts: 206
  • Joined: 10-May 05

Posted 08 November 2006 - 08:36 AM

Have you added the adsi support files?

#3 User is offline   _WearingPants 

  • Group: Members
  • Posts: 2
  • Joined: 08-November 06

Posted 08 November 2006 - 03:36 PM

yes. I can bind to an OU and list all users without any problems.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy