Solved

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

Posted on 2014-07-24
7
200 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

18 Experts available now in Live!

Get 1:1 Help Now