Solved

Use VBcript to List Office Users form Active Directory

Posted on 2010-11-15
7
536 Views
Last Modified: 2012-05-10
I have written vbscript to display a list of users from a particler office filtered
by the Office attribute and it is erroring outwith the message below, what is wromg
with thescript below?

D:\download\myscript1.vbs(15, 2) Microsoft VBScript runtime error: Object doesn't
support this property or method: 'objItem.physicalDeliveryOfficeName'

'On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount",,48)

For Each objItem In colItems

      if objItem.physicalDeliveryOfficeName = "BS" Then
            Wscript.Echo objItem.Name + ", " + objItem.FullName
      end if

Next

Wscript.Echo "Done"
0
Comment
Question by:netimpact
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:rogerard
ID: 34137394
You will get that error when the entry you're reporting doesn't contain the field you're trying to display. ( ie the field is empty(null) and didn't return with the results)
0
 

Author Comment

by:netimpact
ID: 34138314
It says clearly Object doesn't support this property or method: 'objItem.physicalDeliveryOfficeName'

All the records in our AD are NOT null. Could this be the wrong direction?

0
 
LVL 7

Expert Comment

by:rogerard
ID: 34138391
Perhaps a mis-communication?
What I mean is that for the referenced objItem, User1 let say, has no physicalDeliveryOfficeName assigned.  If you go look for User1 in Active directory you'll see that the field for physicalDeliveryOfficeName is blank.

Therefore you'll have an object for User1, but no address.

Clearer?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:netimpact
ID: 34138555
Ok how do I fix this code?
0
 
LVL 7

Accepted Solution

by:
rogerard earned 250 total points
ID: 34139690
The code, in and of itself is valid, except for the reference to physicalDeliveryOfficeName, which is not a member of the Win32_UserAccount class.  You fix it by referencing one of the available properties/methods of the Win32_UserAccount class.  See http://msdn.microsoft.com/en-us/library/aa394507%28VS.85%29.aspx for a list of available attributes.

If you absolutely need to get the physicalDeliveryOfficeName attribute from a user, then you need to query ldap or the global catalog instead.
0
 

Author Comment

by:netimpact
ID: 34140159
You are right I need to absolutely access the physicalDeliveryOfficeName attribute so I need to query LDAP. Thanks for the tip it was just staring me in the face.
0
 

Author Closing Comment

by:netimpact
ID: 34154079
Not the complete solution
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sumDigits challenge 9 150
pre4 challenge 19 100
groupNoAdj 7 95
mapAB Challlenge 35 145
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

773 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