Link to home
Start Free TrialLog in
Avatar of D B
D BFlag for United States of America

asked on

Ignore Items in a List/Array

I have the following line of code:
if ($IsSysObj -ne $true -and $table.FakeSystemTable -ne $true -and $table.Name -ne "ignore_me")
{...}
I want to create an array of table names and replace '-and $table.Name -ne "ignore_me"' with code that will ignore values in that list. Not exactly sure how to accomplish this.
I know how to create the array ($a = "table1", "table2", "table3"...) but what code would I use to exclude values within the array?
Avatar of becraig
becraig
Flag of United States of America image

An if statement sounds like what you need.

do a foreach on your array then do a match on the value and use if /else:

E.g.:
($a = "table1", "table2", "table3"...) 
$a | % {if ($_ -eq "table2") {write-host "Do something"} else {write-host $_ "Do nothing"} }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of D B

ASKER

Works like a champ. Thanks!