Avatar of netimpact
netimpactFlag for United Kingdom of Great Britain and Northern Ireland asked on

Use VBcript to List Office Users form Active Directory

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"
Programming Languages-Other

Avatar of undefined
Last Comment
netimpact

8/22/2022 - Mon
rogerard

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)
ASKER
netimpact

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?

rogerard

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?
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
netimpact

Ok how do I fix this code?
ASKER CERTIFIED SOLUTION
rogerard

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
netimpact

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.
ASKER
netimpact

Not the complete solution
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.