Ignore Items in a List/Array

Posted on 2014-08-18
Last Modified: 2014-08-18
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?
Question by:dbbishop
    LVL 28

    Expert Comment

    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:

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

    Open in new window

    LVL 40

    Accepted Solution

    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

    LVL 15

    Author Closing Comment

    Works like a champ. Thanks!

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Suggested Solutions

    Synchronize a new Active Directory domain with an existing Office 365 tenant
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now