Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
SQL Server
Powershell -contains/-notcontains - having trouble with an array result from SQLServer
Last Post 05 Aug 2010 03:14 PM by
Chad Miller
. 4 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
mg48
New Member
Posts:17
04 Aug 2010 02:01 PM
I am using Invoke-SQLCmd to get a list of items that I want to process. In that list may be an item that indicates that the entire list needs to be bypassed. I have tried to figure out how to use the -contains and -notcontains operator but I am not having any luck. This would be the pseudo code:
$dont_process = "dont process"
$list = Invoke-SQLCmd ........
if ($list -notcontains $dont_process) {processing goes here}
$list is a System.array of DataRows. The operator is supposed to work on an array but I guess an array of DataRows is not the kind it works on. Any help would be greatly appreciated.
Chad Miller
Basic Member
Posts:160
04 Aug 2010 04:33 PM
Since $list is array of DataRows I would suggest using something like this:
if (!($list | where-object {$_.text -eq "dont process"})) {do stuff}
Note in this example text is the name of the SQL table column.
mg48
New Member
Posts:17
05 Aug 2010 05:31 AM
Thanks - after I posted I continued searching and actually found an earlier post by you on technet. I was able to use that to complete this part of the script I am working on. I'll try this out also.
I case you're curious, this is what you posted in June:
$list = New-Object System.Collections.ArrayList
get-sqlcmd2 MyServer MyDatabase "Select X FROM Table Y" | foreach { [void]$list.Add($_.X) }
mg48
New Member
Posts:17
05 Aug 2010 05:41 AM
I I would like to mark this post as "Answered" or "Resolved" but haven't figured out how. Where do I do that?
Chad Miller
Basic Member
Posts:160
05 Aug 2010 03:14 PM
That works too as they in Perl scripting There's More than One Way To Do It.
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
SQL Server
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2