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
Avatar of rogerard
rogerard
Flag of United States of America image

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)
Avatar of netimpact
netimpact
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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?

Avatar of rogerard
rogerard
Flag of United States of America image

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?
Avatar of netimpact
netimpact
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Ok how do I fix this code?
ASKER CERTIFIED SOLUTION
Avatar of rogerard
rogerard
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of netimpact
netimpact
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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.
Avatar of netimpact
netimpact
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Not the complete solution
Programming Languages-Other
Programming Languages-Other

A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. Thousands of different programming languages have been created, mainly in the computer field, and many more still are being created every year. The description of a programming language is usually split into the two components of syntax (form) and semantics (meaning). Some languages are defined by a specification document (for example, the C programming language is specified by an ISO Standard), while other languages (such as Perl) have a dominant implementation that is treated as a reference. Some languages have both, with the basic language defined by a standard and extensions taken from the dominant implementation being common.

20K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo