Solved

VBScript If INSTR Using A List of Values to Check

Posted on 2010-11-09
7
1,046 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:jeffmowens
Comment Utility
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
Comment Utility
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 300 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Assisted Solution

by:jeffmowens
jeffmowens earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sure, no problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Move Profile Subfolders to new location 2 33
VBA code shorten run time 4 40
Custom auto number 6 51
Script is being strange 8 48
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

10 Experts available now in Live!

Get 1:1 Help Now