?
Solved

Use VBcript to List Office Users form Active Directory

Posted on 2010-11-15
7
Medium Priority
?
569 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Accepted Solution

by:
rogerard earned 750 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

830 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