Solved

Remove machines from ADS

Posted on 2007-03-19
69
283 Views
Last Modified: 2010-03-05
Hi,

I have a list of machines in a TXT file.How do i delete all the file name on that list from the ADS.

Regareds
Sharath
0
Comment
Question by:bsharath
  • 37
  • 31
69 Comments
 
LVL 69

Expert Comment

by:Merete
ID: 18754674
Are we talking about Hosts files/
http://www.accs-net.com/hosts/how_to_use_hosts.html
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18755183
Presumably you mean from Active Directory?

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = objConnection
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM 'LDAP://dc=company,dc=com' WHERE objectCategory='computer' And Name='"  & PC & "'"
Set objRS = objCommand.Execute
If Not objRS.EOF Then
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If

Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18755186
Save that as DelPC.vbs
Modify the LDAP://dc=company,dc=com string to read your domain, and update the location of machines.txt to run it...
0
 
LVL 11

Author Comment

by:bsharath
ID: 18761374
sirbounty:

How can i find the LDAP://

When i ping my domain name i get as ****.***.**.* should i specify four dc=

Regards
Sharath
0
 
LVL 11

Author Comment

by:bsharath
ID: 18761377
I get this error

C:\>cscript ads.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\ads.vbs(25, 19) Microsoft VBScript compilation error: Expected 'Next'


I have made the changes as you mentioned
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18761378
when you ping the domain - you're probably getting the ip address...

111.22.33.44

You need the domain name.
Example - microsoft.com would be LDAP://dc=microsoft,dc=com
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18761385
I missed a Next - at the very bottom of this section (just after the End If)

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM 'LDAP://dc=company,dc=com' WHERE objectCategory='computer' And Name='"  & PC & "'"
Set objRS = objCommand.Execute
If Not objRS.EOF Then
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If
Next '<<<added
0
 
LVL 11

Author Comment

by:bsharath
ID: 18761411
Hi,

This comes out without an error but the machine name is still present on the ADS if i search

THX
Sharath
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18761415
Try this...it should display if it is deleting or not...

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = objConnection
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM 'LDAP://dc=company,dc=com' WHERE objectCategory='computer' And Name='"  & PC & "'"
Set objRS = objCommand.Execute
If Not objRS.EOF Then
wscript.echo "Removing " & objRS.Fields(0)
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If
Next
Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing
0
 
LVL 11

Author Comment

by:bsharath
ID: 18761439
Hi,

I get this


C:\>cscript ads.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

If i ping my domain name it shows as

horse.infomatic.junk.co

So should i mention as

LDAP://dc=horse,dc=infomatic,dc=junk,dc=co


0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18761445
Would you have root access to the domain?
0
 
LVL 11

Author Comment

by:bsharath
ID: 18761453
yes

i am doing this on a domain admin login and on the ads itself

i have even tried from a different machine which has administrator access
0
 
LVL 11

Author Comment

by:bsharath
ID: 18761466
In the file machines.txt should i mention only the machine name or \\machines name
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18761472
just the machine name
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18761476
Okay - try this version and you won't have to enter the domain..

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Dim objRoot: Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain: Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & "' WHERE objectCategory='computer' And Name='" & PC & "'"
Set objRS = objCommand.Execute
If Not objRS.EOF Then
wscript.echo "Removing " & objRS.Fields(0)
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If
Next
Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing
0
 
LVL 11

Author Comment

by:bsharath
ID: 18761478
I get this error.

C:\>cscript ads.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\ads.vbs(17, 1) Microsoft VBScript runtime error: Object required: 'objCommand
'
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18763072
Set objRS = objCommand.Execute
should be
Set objRS = cmd.Execute
0
 
LVL 11

Author Comment

by:bsharath
ID: 18763497
Hi,

I have made the changes but still the machine name which i have mentioned does not delete from the ads
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18763512
Does it even get to this line?
wscript.echo "Removing " & objRS.Fields(0)

It should be displaying that on-screen...
0
 
LVL 11

Author Comment

by:bsharath
ID: 18763566
No  error or notification
0
 
LVL 11

Author Comment

by:bsharath
ID: 18763578
Just this


C:\>cscript ads.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18763584
So, it's not even starting the loop through the recordset.
Modify it like this:

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & "' WHERE objectCategory='computer' And Name='" & PC & "'"
Set objRS = objCommand.Execute
wscript.echo PC '<<<can I know what is returned here?
msgbox objRS.Count '<<and here
0
 
LVL 11

Author Comment

by:bsharath
ID: 18763612
This error
C:\>cscript ads.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\ads.vbs(19, 31) Microsoft VBScript compilation error: Expected 'Next'
0
 
LVL 11

Author Comment

by:bsharath
ID: 18763630
Please give me the full script again
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18763633
Full code...

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Dim objRoot: Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain: Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & "' WHERE objectCategory='computer' And Name='" & PC & "'"
Set objRS = cmd.Execute
wscript.echo PC '<<<can I know what is returned here?
msgbox objRS.Count '<<and here
If Not objRS.EOF Then
wscript.echo "Removing " & objRS.Fields(0)
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If
Next
Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing
0
 
LVL 11

Author Comment

by:bsharath
ID: 18763721
I get this error


C:\>cscript ads.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

dev-chen-pc100
C:\ads.vbs(19, 1) Microsoft VBScript runtime error: Object doesn't support this
property or method: 'objRS.Count'
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18763743
Hmm...replace this line
msgbox objRS.Count '<<and here
with this one
msgbox objRS.RecordCount

0
 
LVL 11

Author Comment

by:bsharath
ID: 18763777
Now i get a box with a 0 and when i check the ads the machine name still exists.

THX
Sharath
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18763824
Because for some reason the recordset isn't pulling back any data...

This defines our query...
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & "' WHERE objectCategory='computer' And Name='" & PC & "'"

So, let's see what's in it when it's run...use this version:

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Dim objRoot: Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain: Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & "' WHERE objectCategory='computer' And Name='" & PC & "'"
wscript.echo cmd.CommandText '<<need this information
Set objRS = cmd.Execute
If Not objRS.EOF Then
wscript.echo "Removing " & objRS.Fields(0)
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If
Next
Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing
0
 
LVL 11

Author Comment

by:bsharath
ID: 18763936
Now this


C:\>cscript ads.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\ads.vbs(2, 1) Microsoft VBScript runtime error: Object required: ''
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18763965
<sigh>...it's the wrapping on the site...this should all be on one line...or let's split it to be sure...

cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & _
  "' WHERE objectCategory='computer' And Name='" & PC & "'"
0
 
LVL 11

Author Comment

by:bsharath
ID: 18763980
The same erro even after putting these lines in 2 rows
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18764040
Oh wait, line 2 is this line:

arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Is machines.txt no longer there?
0
 
LVL 11

Author Comment

by:bsharath
ID: 18764069
Its like this

cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & "' WHERE objectCategory='computer' And Name='" & PC & "'"
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Dim objRoot: Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain: Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & _
  "' WHERE objectCategory='computer' And Name='" & PC & "'"

wscript.echo cmd.CommandText '<<need this information
Set objRS = cmd.Execute
If Not objRS.EOF Then
wscript.echo "Removing " & objRS.Fields(0)
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If
Next
Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing



There is machines.txt file in c:\
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18764075
Sorry - use this...

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Dim objRoot: Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain: Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

For each PC in arrData
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & _
                    "' WHERE objectCategory='computer' And Name='" & PC & "'"
wscript.echo cmd.CommandText '<<need this information
Set objRS = cmd.Execute
If Not objRS.EOF Then
wscript.echo "Removing " & objRS.Fields(0)
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If
Next
Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing

0
 
LVL 11

Author Comment

by:bsharath
ID: 18764133
I dont get any error.


C:\>cscript ads.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

SELECT adsPath FROM 'LDAP://DC=junk,DC=com' WHERE obj
ctCategory='computer' And Name='dev-chen-pc1292'

But the machine name is still present in the ADS
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18764394
Odd...it appears that its simply not finding that computer name.
For all intents and purposes this should be working.  Can you verify the computer name or create a test computer name to try it against?
0
 
LVL 11

Author Comment

by:bsharath
ID: 18764420
Ok i shall try and get back to you
0
 
LVL 11

Author Comment

by:bsharath
ID: 18764449
Will this script add the machine or delete?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18764465
objPC.DeleteObject (0) 'deletes per this line...
0
 
LVL 11

Author Comment

by:bsharath
ID: 18764481
I have checked with a different machine name and even created one new machine then tried the command the same display and the machine is still presend in the ads
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18764580
Tough to say why the query isn't returning those items...

If you can get at the full DN of the computer object, then try something like this in a script (change it to reflect your container OU)

Set objPC=GetObject ("LDAP://CN=chen-pc1292, CN=Computers, DC=horse, dc=infomatic,dc=junk,dc=co") 'I'm assuming that's the full path? if it's not in an OU
objPC.DeleteObject (0)

If that doesn't work, then something else is going on here...
0
 
LVL 11

Author Comment

by:bsharath
ID: 18764786
The cononical name of the object.

This would be the location

Development.junk.co.uk/Computers/DEV-CHEN-PC1291

Please tell me how i need to mention in the script
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18764853
Set objPC=GetObject ("LDAP://cn=DEV-CHEN-PC1291, cn=Computers, DC=development,dc=junk,dc=co,dc=uk")
objPC.DeleteObject (0)

That should do it - just name that as Delete1PC.vbs and see if it works...
0
 
LVL 11

Author Comment

by:bsharath
ID: 18764980
Hi,

Dev-chen-pc1291 is the machine name which is unders a OU called computers and the domain name is
Development.co.uk

How do i do it.Please advice.

regards
Sharath
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18765059
Is it an OU named computers, or the default Computers container?

Set objPC=GetObject ("LDAP://cn=DEV-CHEN-PC1291, cn=Computers, DC=development,dc=co,dc=uk")
objPC.DeleteObject (0)
0
 
LVL 11

Author Comment

by:bsharath
ID: 18765183
Default is computers container

I get this error

C:\>cscript a.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\a.vbs(2, 1) Microsoft VBScript runtime error: Permission denied

But i have logged in to a domain admin login which has total rights on the domain
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18765203
Does this return the computer?

Set objPC=GetObject ("LDAP://cn=DEV-CHEN-PC1291, cn=Computers, DC=development,dc=co,dc=uk")
msgbox objPC.Name
objPC.DeleteObject (0)
0
 
LVL 11

Author Comment

by:bsharath
ID: 18765235
Yes it shows a box with

Cn=dev-chen-pc1291
0
 
LVL 11

Author Comment

by:bsharath
ID: 18765242
After i clicked ok on the box it shows.


C:\>cscript a.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\a.vbs(3, 1) Microsoft VBScript runtime error: Permission denied
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18765378
Hmm. - not sure how to troubleshoot that...if it's a permission denied message, then it seems you don't have permission - can you do it through the mmc?  Start->Run->Dsa.msc
0
 
LVL 11

Author Comment

by:bsharath
ID: 18765532
when i type dsa.msc it opens the active directory users and computers console
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18765542
Correct - and if you perform a search (or manually locate) for that computer - can you delete it from there?
0
 
LVL 11

Author Comment

by:bsharath
ID: 18765560
Yes i just delete the machine manually

From the ADS console
0
 
LVL 11

Author Comment

by:bsharath
ID: 18769393
Thanks a lot for all the help provided.I need this as it is very useful for me.Can you please help me.

THX
Sharath
0
 
LVL 11

Author Comment

by:bsharath
ID: 18777727
sirbounty:

Any more help on this
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18779210
I'm not sure on a permission denied, what else to try...
I created a test object on my domain and the code above worked fine.  I suspect maybe something else is going on here... : (
0
 
LVL 11

Author Comment

by:bsharath
ID: 18887178
Hi Sirbounty:

Can you please post me the code for the last time with all the changes made.

I shall try again.

THX
Sharath
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18887398
This 'should' work...I'm still not sure why it doesn't for you...
I've added some more 'tests'...

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
arrData=Split(objFSO.OpenTextFile("C:\machines.txt").ReadAll, vbNewLine)

Dim objRoot: Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain: Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
if err.number <> 0 Then wscript.echo "Error detected: " & err.description

Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
if err.number <> 0 Then wscript.echo "Error detected: " & err.description

For each PC in arrData
wscript.echo "Checking " & PC 'This should return 'just' the PC name - not the \\PCName version <<<<

cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & _
                    "' WHERE objectCategory='computer' And Name='" & PC & "'"

wscript.echo cmd.CommandText 'is the query definition

Set objRS = cmd.Execute

If Not objRS.EOF Then
wscript.echo "Removing " & objRS.Fields(0)
  objPC=GetObject(objRS.Fields(0))
  objPC.DeleteObject (0)
  Set objPC=Nothing
End If
Next
Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing
0
 
LVL 11

Author Comment

by:bsharath
ID: 18887413
1. Where all does this search for the machine
If we need to specify the location where can i do it.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18887416
What's in your C:\Machines.txt file right now?
0
 
LVL 11

Author Comment

by:bsharath
ID: 18887418
I am getting the machine name in a box then another box with the CN and DC's.
0
 
LVL 11

Author Comment

by:bsharath
ID: 18887425
C:\>cscript abc.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Checking dev-chen-mrd100
SELECT adsPath FROM 'LDAP://DC=Development,DC=iSOFTGroup,DC=co,DC=uk' WHERE obje
ctCategory='computers' And Name='dev-chen-mrd100'
0
 
LVL 11

Author Comment

by:bsharath
ID: 18887429
dev-chen-mrd100 is the machine name which is there
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18887438
Try this version for testing...

Dim objRoot: Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain: Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & _
                    "' WHERE objectCategory='computer'"
Set objRS = cmd.Execute

If Not objRS.EOF Then
  wscript.echo objRS.Fields(0).Value & " found!"
  objPC=GetObject(objRS.Fields(0))
  wscript.echo objPC.adsPath & " path is found!"  
  Set objPC=Nothing
End If
Set cmd=Nothing
Set cn=Nothing
Set objFSO=Nothing

Hopefully you'll get those two 'found' lines...?
0
 
LVL 11

Author Comment

by:bsharath
ID: 18887453
No errors or any result.But still the machine is available in the ADS
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18887459
That should have found 'any' machine - not just the one in the text file...
Hmm...one more test and I have to head off.

Try this - it may take a while, but it'll let us know that it's getting through to your computers...it should just display 'every' computer in your domain...may take a bit to run through - you can stop it by <ctrl> + <break> if needed...

Dim objRoot: Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain: Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
Set cn = CreateObject("ADODB.Connection")
Set cmd =   CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.Properties("Page Size") = 1000
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
cmd.CommandText = "SELECT adsPath FROM '" & objDomain.aDSPath & _
                    "' WHERE objectCategory='computer'"
Set objRS = cmd.Execute

Do While Not objRS.EOF
  wscript.echo objRS.Fields(0).Value & " found!"
  objRS.MoveNext
Loop
Set cmd=Nothing
Set cn=Nothing
0
 
LVL 11

Author Comment

by:bsharath
ID: 18887509
This just came out without any process.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18888684
Again, I'm stuck - this should have returned a lot of results...
I'm not sure what the issue is at this piont.
0

Join & Write a Comment

The Need In an Active Directory enviroment, the PDC emulator provide time synchronization for the domain. This is important since Active Directory uses Kerberos for authentication.  By default, if the time difference between systems is off by more …
Synchronize a new Active Directory domain with an existing Office 365 tenant
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now