?
Solved

VBScript If INSTR Using A List of Values to Check

Posted on 2010-11-09
7
Medium Priority
?
1,127 Views
Last Modified: 2012-05-10
I'm running a report that lists all Active Directory Accounts and lists the following: User ID, Full Name, Description, Email Address, and Employee Type. The goal being to list all but service type accounts.

I've noticed some discrepancies where some accounts are listed as Generic, but they are actual user accounts. I can clean these up easily enough with another script, but my main concern is giving someone this report with everything already removed regardless of whether these discrepancies exist or not. The easiest way is skip files that have certain strings in the Description or User ID.

So if I use the following code:
If InStr(objUser.Description, "Workstation") Then objRecordSet.MoveNext

Is there a way to check for a list of strings, and most importantly, to see if a numeric value exists without a ridiculously long If, Then, Else If statement?

Thanks!!
0
Comment
Question by:JB4375
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:jeffmowens
ID: 34095292
This will look for the Description in the comma-delimited list of objects you want to skip. Note that both portions of the comparision need to be wrapped in commas as exampled below:

If InStr(1, ","&objUser.Description&","   ,  ",Workstation,Computer,Group," ) > 0 Then
  ' MoveNext
  ...
0
 
LVL 1

Author Comment

by:JB4375
ID: 34096230
OK...
Remarkably simple. Is there any limit to the number of items in the comma-delimited list?
Thanks again!!
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 1200 total points
ID: 34097847
Hi,

To my knowledge, that doesn't work.  InStr will not treat ",Workstation,Computer,Group," as a comma separated list to look for in objUser.Description.  That will match only when the full string of ",Workstation,Computer,Group," is actually in the description.

What you might need to do is create a dictionary of excluded words or phrases and check if any of them exist in any attribute you're after.

Regards,

Rob.
Set objExcludes = CreateObject("Scripting.Dictionary")
objExcludes.Add "Workstation", 0
objExcludes.Add "Computer Model", 0
objExcludes.Add "Group", 0

While Not objRS.EOF
	bSkip = False
	For Each strExclude In objExcludes
		If InStr(LCase(objUser.Description), LCase(strExclude)) > 0 Then
			bSkip = True
			Exit For
		End If
	Next
	If bSkip = False Then
		'....add the record to the file, otherwise if bSkip is true, this block will not be executed
	End If
	objRS.MoveNext
Wend

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Assisted Solution

by:jeffmowens
jeffmowens earned 800 total points
ID: 34098455
Yes, it will work; and I don't think there is a string length limit.  

However, after looking at my example again, I see I have the order of the string parameters reversed. It should be:

InStr([Start Position] , [String To Search] , [String To Find])

thus;

If InStr( 1, ",Workstation,Computer,Group," , ","&objUser.Description&"," ) > 0 Then

...would look for the Description inside of the list.


0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34098726
Oh right.  That makes more sense.  So if the Description value was either of the following:
Workstation
Computer
Group

it would work.  This does match the *entire* description though, so if the description were My Workstation, it would not find a match.  This would probably work for the author.

Thanks for clarifying.

Rob.
0
 
LVL 1

Author Closing Comment

by:JB4375
ID: 34101781
Thanks guys!!

Rob I liked you approach because it seems easier to included a list of items, without dealing with all the syntaxt, AND it also deals with handling case. Something I hadn't even considered.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34106192
Sure, no problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

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.

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…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 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