Solved

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

Posted on 2014-07-24
7
202 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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