Find computers, which are not disabled, in AD via script

R

Rytis

Does anybody knows, how to find all computers from AD, which are not
disabled via vbs script?

I am trying to do like this:

com.CommandText = "select name " & _
"from 'LDAP://ou=Computers,DC=xx,DC=xxx,DC=xx' " & _
"where objectClass = 'Computer' and UserAccountControl <> 'True'"
Set rec = com.Execute

but this one doesn't work :-(

Thanks.
 
M

Mike Shepperd [MSFT]

I'm not entirely clear on what you're trying to accomplish. If you just
want to create a list of computer accounts from Active Directory, you can
use the ListMembers.vbs script from the Windows 2000 Resource Kit as a
starting point. Here's a sample syntax and output:

listmembers.vbs WinNT://domainname /C:computer
Getting object WinNT://MyDomain...
Getting members of WinNT://MyDomain
computer 1 WinNT://MyDomain/Server1
computer 2 WinNT://MyDomain/Server2
computer 3 WinNT://MyDomain/DC1
computer 4 WinNT://MyDomain/DC1
computer 5 WinNT://MyDomain/Member1
computer 6 WinNT://MyDomain/Exchange1
Object WinNT://MyDomain" has 6 computer members.

If this is not what you're trying to do, please reply with a clear
indication of what you need to accomplish.

Thanks,

--
Mike Shepperd MCSE Windows 2000/NT 4.0
Support Engineer
Enterprise Platforms Support
Directory Services Team

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

--------------------
| From: "Rytis" <[email protected]>
| Subject: Find computers, which are not disabled, in AD via script
| Date: Thu, 26 Feb 2004 17:42:01 +0200
| Lines: 15
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.win2000.active_directory
| NNTP-Posting-Host: proxy.telecom.lt 212.59.0.201
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.win2000.active_directory:68207
| X-Tomcat-NG: microsoft.public.win2000.active_directory
|
| Does anybody knows, how to find all computers from AD, which are not
| disabled via vbs script?
|
| I am trying to do like this:
|
| com.CommandText = "select name " & _
| "from 'LDAP://ou=Computers,DC=xx,DC=xxx,DC=xx' " & _
| "where objectClass = 'Computer' and UserAccountControl <> 'True'"
| Set rec = com.Execute
|
| but this one doesn't work :-(
|
| Thanks.
|
|
|
 
R

Rytis

I need to get a list of computers, which are in particular OU, and which are
not disabled.
And this is only a part from my script. It is responsible to select only
computer, which is not disabled.
So I need information, how to check that computer is not disabled. If change
a line to:

"where objectClass = 'Computer' and description <> 'X*'"

I can filter out computers, which have something in "description" property.
So I need to filter out disabled computers.
 
Joined
May 22, 2008
Messages
1
Reaction score
0
Disabled Computers

'Found this script on the 'net, riffed it a little for computer accounts
'Almost the same for disabled user accounts.
Sub ListDisabledComputers()
Dim strDomainDN As String
Dim strBase As String
Dim strFilter As String
Dim strAttrs As String
Dim strScope As String
Dim objConn As ADODB.Connection
Dim objRS As ADODB.Recordset
strDomainDN = "<<DomainName>>" ' e.g. dc=rallencorp,dc=com

strBase = "<LDAP://" & strDomainDN & ">;"
strFilter = "(&(objectclass=computer)(useraccountcontrol:1.2.840.113556.1.4.803:=2));"
strAttrs = "name;"
strScope = "subtree"

Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
Set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)
objRS.MoveFirst
While Not objRS.EOF
'Wscript.Echo objRS.Fields(0).Value
'Debug.Print objRS.Fields(0).Value
objRS.MoveNext
Wend
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top