Solved

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

Posted on 2014-07-24
7
201 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

15 Experts available now in Live!

Get 1:1 Help Now