Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to disable computer account, don't know LDAP DN 1

Status
Not open for further replies.

Jerz

MIS
Sep 10, 2004
102
US
I have a TXT file list of computers to disable or delete. I can delete with:
Code:
Set DomainObj = GetObject("WinNT://" & "DomainNameString")
DomainObj.Delete "computer", "ComputerNameString"

I've seen code which is supposed to disable, but it uses GetObject("LDAP://" CN=, OU=, OU=, etc), which I don't have, the computer objects on the list are scattered all over the AD.
Code:
Set objComputer = GetObject("LDAP://" & strComputerDN, vbNullString)
objComputer.AccountDisabled = True
objComputer.SetInfo

I'm wanting something like this, only that works:)
Code:
Set CompObj = GetObject("WinNT://" & "DomainNameString" &  "ComputerNameString","computer")
CompObj.AccountDisabled = True
CompObj.SetInfo
but this gives me 'error, Activex component can't create object' on the first line.

Can anyone tell me how to either disable the AD computer account using GetObject("WinNT://....., or tell me how to derive the Distingushed Name from it so I can do it using the GetObject("LDAP://"........?

Thanks,
Jerz
 
Hello Jerz,

The proper binding string is:
[tt]
Set CompObj = GetObject("WinNT://" & "DomainNameString" & "/" & "ComputerNameString" & ",computer")
[/tt]
where DomainNameString and ComputerNameString are string literals, I suppose. If they are variable names having values of a string, then take out the quotes surrounding them.

regards - tsuji
 
Thanks, tsuji.

The statment syntax now works, but WinNT still gets an error "The network path was not found". This is likely because the PC in question no longer exists anywhere except the OU & Domain. I can bind using LDAP and disable successfully, but only if I know all the OU's leading to the computer object. Is there any way to bind via LDAP when all you have to go on is Domain name & Computer name?

I thought the AdsPath might be it, but it's just the WinNT bind object regurgitated. Is the "Fully qualified Domain Name of object" property available using WinNT? Is there a list somewhere of specifically what properties are available via WinNT? I've tried looking on MS, but I keep getting lost.

Thanks,
Jerz
 
It appears that I should be able to retrieve something called a GUID using the WinNT provider and something called IADsComputer, but I can't get it to process.
When I do:
Code:
Dim CompObj as IADsComputer
I get 'error: Expected end of statement' at the 'a' in as, char 13.

 
Jerz,

You've to look into the iadsnametranslate interface. Roughly like this as a demo.
Code:
'nt data might be got from wshnetwork for instance
snbdom="a0b1c2"
snode="d3e4f5"

set otrans=createobject("nametranslate")
with otrans
	.init 3,""
	.set 3,snbdom & "\" & snode & "$"
end with
sdn=otrans.get(1)
set onode=getobject("LDAP://" & sdn)
- tsuji
 
Sweet! tsuji you are a genius!

This is exactly what I'm looking for. I've still no understanding of what it's doing, but I can plug in the Domain & defunct PC name on one end, and bind LDAP on the other. Too cool.

Thanks so much!
Jerz
 
i am having the exact same issue as jerz started out with. i am confused as to tsuji's last message & how it works with the script, could you show how that relates to the rest of the script?

thanks
 
Here's what I ended up with, minus the logging file stuff...

Code:
'Gets the domain of machine it's running on
Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_ComputerSystem")
for each System in SystemSet
 curDom = system.Domain
next
Dom = curDom
'Misc. var setting
count = 0
On Error Resume Next
Const ForReading = 1
'*  Read Computer Name from each line in workfile  * 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(path & "pending\workfile.txt", ForReading)
Do While objTextFile.AtEndOfStream <> True
  strLinetoParse = objTextFile.ReadLine
  NameLength = Instr(strLinetoParse, " ") - 1
' Skip the first line because it is blank
  If NameLength > 0 then 
    Computer = Mid(strLinetoParse, 1, NameLength)
    CompAge = Mid(strLinetoParse, 42, 3)
    DomainString = """" & Dom & """"
    compString = """" & Computer & """"
'*           Connect to the Computer               *
    set otrans=createobject("nametranslate")
    with otrans
        .init 3,""
        .set 3,dom & "\" & computer & "$"
    end with
    sdn=otrans.get(1)
    set CompObj = getobject("LDAP://" & sdn)
'*            Disable the Computer                 * 
    CompObj.AccountDisabled = True
    CompObj.SetInfo

Note: Workfile txt is ouput from NewPWAge.exe, Copyright 1999 Marty List, OptimumX@usa.net.

Hope this helps....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top