Solved

Use VBcript to List Office Users form Active Directory

Posted on 2010-11-15
7
518 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
java ^ examples 8 57
post4 challenge 28 83
sumHeights2  challenge 7 78
Non-recursive backtracking, using a stack 1 53
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This video teaches viewers about errors in exception handling.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

746 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

9 Experts available now in Live!

Get 1:1 Help Now