Link to home
Start Free TrialLog in
Avatar of BakerSyd
BakerSydFlag for Australia

asked on

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

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!
Avatar of BakerSyd
BakerSyd
Flag of Australia image

ASKER

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"
ASKER CERTIFIED SOLUTION
Avatar of Chris Watson
Chris Watson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks Chris, i will try this out tomorrow at work and let you know how it goes


cheers!
Chris, thats working perfectly..

can you explain why you added the Len(Trim(objProperty)) part?
i dont understand this..
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"
appreciate the explanation and your help

thanks!
perfect