Solved

vbs code to detect null entry in active directory and output accordingly

Posted on 2014-07-24
7
205 Views
Last Modified: 2014-07-25
heya

i need a simple IF script that will detect a null entry in the mobile field in active directory
ive looked at isNull and isEmpty but i dont really understand how to get the info from AD


i need the code to do something like this


IF(there is no number in the mobile field) then 
    do this
Else 
   do this
end IF

Open in new window


im not sure if im on the right track here...

im not sure if its meant to be

IF IsNull(g_objldapuser.mobile)
then
blah
else
blah
end if

Open in new window



g_objldapuser has already been specified in a different sub so g_objldapuser.mobile does work if you do a wscript.echo, it will show the correct output.


thanks for your help!
0
Comment
Question by:BakerSyd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 

Author Comment

by:BakerSyd
ID: 40216879
i have also tried this sort of logic

	objProperty = g_objldapuser.mobile ("")
	if IsNull (objProperty) then
		wscript.echo "no number"
	else	
		wscript.echo "yes number"
	end if

Open in new window


this seems to work... but even thou there is no number in AD it still says "yes number"
0
 
LVL 4

Accepted Solution

by:
Chris Watson earned 500 total points
ID: 40217009
I'll assume that objProperty does contain the correct value as you say that it echoes the expected value. The below should catch Null values and empty strings.

objProperty = g_objldapuser.mobile ("")
If IsNull (objProperty) Or Len(Trim(objProperty)) = 0 Then
    Wscript.Echo "no number"
Else
    Wscript.Echo "yes number"
End If

Open in new window

0
 

Author Comment

by:BakerSyd
ID: 40217549
thanks Chris, i will try this out tomorrow at work and let you know how it goes


cheers!
0
Technology Partners: 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:BakerSyd
ID: 40218816
Chris, thats working perfectly..

can you explain why you added the Len(Trim(objProperty)) part?
i dont understand this..
0
 
LVL 4

Expert Comment

by:Chris Watson
ID: 40219026
IsNull (objProperty) tests for Null values

Len(Trim(objProperty)) = 0 tests for empty strings (e.g. "") and strings consisting entirely of whitespace (e.g. " ").

Len() returns the length of a string. e.g. Len("BakerSyd") = 8

Trim() removes any leading and trailing whitespace. e.g. Trim(" BakerSyd ") = "BakerSyd"
0
 

Author Comment

by:BakerSyd
ID: 40219051
appreciate the explanation and your help

thanks!
0
 

Author Closing Comment

by:BakerSyd
ID: 40219052
perfect
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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