[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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?
0
dbbishop
Asked:
dbbishop
1 Solution
 
becraigCommented:
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

0
 
SubsunCommented:
To create list..
$a = "table1", "table2", "table3"

Open in new window

To ignore the contents of the list use -notcontains operator..
'-and $a -notcontains $table.Name'

Open in new window

0
 
dbbishopAuthor Commented:
Works like a champ. Thanks!
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now