Question, I’d like to be able to compare a list of objects against an array of strings. More or less, like using the Sql ‘IN’ operator (where TableName IN(‘Table1′,’Table2′,’Table3’).
Specifically, I’m using the SMO table list, and I’d like to return only the tables by name that are contained within an array of table names.
For example:
$tablelist = @(“Address”,”Phone”, “Email”)
sl “SQLSERVER:SQL\SERVERNAME\DEFAULT\DATABASES\DATABASEName\TABLES”
$tables = gci | where{$_.Name –> wtf do I do here with the $tablelist, if this is possible?}
TIA!
B
Update:
Seems like
-inis added in v3.0. Assumed that it was there all along!So in v2.0, you have to use
-containsor-eq:or
There are multiple operators that you can use:
The
-inoperator is similar to what you are used to in SQL. When used with array,-eqsees if the element is present in the array and returns the element if so. So you can use it likeif($a -eq 1)So in your case, you can do something like: