I am trying to filter some tables from my database which exists in my solution folder. I want to filter all tables that I am pulling from SQL Server:
$existingTables = "Table1", "Table2", "Table3", "Table4"
#getting all tables except existing ones
#SqlQuery = "SELECT name FROM sys.Tables order by name asc"
$filteredTables = ((Invoke-SQL -DataSource $ServerName -DatabaseName $DatabaseName -UserID $UserID -Password $Password -SqlCommand $SQLQuery).name | ? {$_ -notcontains $existingTables})
#$filteredTables returns all tables, including the existing ones...
I've tried $_.name and it is the same result.
where name not in()into the select statement?$_ -notcontains $addedTables->$addedTables -notcontains $_. You switched the operands. For-[not]containsthe correct order is<reference_array> -notcontains <item>. Otherwise use-[not]in(<item> -notin <reference_array>). The latter is not available prior to PowerShell v3, though.$addedTablesbe$existingTables?