Checking if System.Object[] contains a value

This isn’t the most interesting of blog posts admittedly.  But I was using the SQL Server Management Objects in my PowerShell script to return a result set from a stored procedure in SQL server.  The data set returned from the Invoke-sqlcmd command was a System.Object[] type.  I wanted to see if a column (the Department column) in the result set contained a specific value. So firstly I obtained the result set like so:

In PowerShell 3 it was a trivial exercise:

however in PowerShell 2 it required slightly more legwork, and was a little slower to run:

 

 

2 thoughts on “Checking if System.Object[] contains a value

Leave a Reply

Your email address will not be published. Required fields are marked *