header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Powershell -contains/-notcontains - having trouble with an array result from SQLServer
Last Post 05 Aug 2010 03:14 PM by Chad Miller. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
mg48User is Offline
New Member
New Member
Posts:17
Avatar

--
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 MillerUser is Offline
    Basic Member
    Basic Member
    Posts:160
    Avatar

    --
    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.
    mg48User is Offline
    New Member
    New Member
    Posts:17
    Avatar

    --
    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) }
    mg48User is Offline
    New Member
    New Member
    Posts:17
    Avatar

    --
    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 MillerUser is Offline
    Basic Member
    Basic Member
    Posts:160
    Avatar

    --
    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.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer