Solved

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

Posted on 2014-07-24
7
204 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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