Login | |
|
 |
Re: Table Does not Exist on searching user name in AD - 4/14/2005 9:27:45 AM
|
|
 |
|
| |
abrarmuhib
Posts: 3
Score: 0
Joined: 4/14/2005
From: USA
Status: offline
|
Dear All, Need your help and guidance. I am using the following code snippet to check for the existence of a computer object in the active directory with the same name as the name of the computer on which my code is running. The intention is to search the object and delete it ,if present and then add the current computer to the domain in a different OU. Here is the code ------------------------------------------------- on error resume next Set WshNetwork = CreateObject("WScript.Network") compName = WshNetwork.COMPUTERNAME wscript.echo compName Set objConnection = CreateObject("ADODB.Connection") objConnection.Open "Provider=ADsDSOObject;UserID=user;Password=pwd;" wscript.echo err.description Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection objCommand.CommandText = "<LDAP://OU=abc,OU=xyz,OU=pqr,DC=ghi,DC=mybank,DC=com>;(cn=" &_ compName & ");distinguishedName;subtree" wscript.echo objCommand.CommandText Set objRecordSet = objCommand.Execute wscript.echo err.description & err.number While Not objRecordset.EOF strDN = objRecordset.Fields("distinguishedName") objRecordSet.MoveNext Wend set objConnection = nothing -------------------------------------------------------- This code snippet will indicate that the object exists or not and then i can take appropriate actions. Issues :: 1. this code works beautifully if i run it on a computer which is already a part of that domain and when i have logged in as a domain user with appropriate rights. 2.If i run this code from the same computer by logging with a non domain id(local computer id), this code does not run. The error it gives is "Table does not exists". This happens even when i give the domain administrative id and password while making the ADODB connection in the code above. 3. This code also fails when the computer i am running it from is not in the domain altogether. Guidance_ I need to know 1. Is it possible for a computer to query a domain controller when it is not in the domain. 2. If yes, what changes should i do in my code to achieve that. Your help and guidance can save some hair. I have been snaching them to resolve this. Thanks, Abrar
|
|
| |
|
|
|
 |
Re: Table Does not Exist on searching user name in AD - 4/14/2005 10:30:32 AM
|
|
 |
|
| |
token
Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
|
You said, "I am using the following code snippet to check for the existence of a computer object in the active directory with the same name as the name of the computer on which my code is running." I dont' think it's possible to have a duplicated computer names exist anywhere in AD. Do you ever get 2 computers returned when running through the recordset ? I think your untimate goal is to determine whether there is a computer account in AD that has that same account name as the local computer from which the script is executing. If so, remove/re-create it. Replace: objCommand.CommandText = "<LDAP://OU=abc,OU=xyz,OU=pqr,DC=ghi,DC=mybank,DC=com>;(cn=" &_ compName & ");distinguishedName;subtree" with: objCommand.CommandText = "<LDAP://DC_NAME/OU=abc,OU=xyz,OU=pqr,DC=ghi,DC=mybank,DC=com>;(cn=" &_ compName & ");distinguishedName;subtree"
|
|
| |
|
|
|
|
|