Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript If INSTR Using A List of Values to Check

Posted on 2010-11-09
7
Medium Priority
?
1,146 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 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