Why can't i call Contains method from my array?

Posted by xbnevan on Stack Overflow See other posts from Stack Overflow or by xbnevan
Published on 2010-05-28T17:08:54Z Indexed on 2010/05/28 17:12 UTC
Read the original article Hit count: 151

Filed under:

Arrrg!I am running into what i feel is a dumb issue with a simple script i'm writing in powershell. I am invoking a sql command that is calling a stored proc, with the results i put it a array. The results look something like this:

Status                                       ProcessStartTime                            ProcessEndTime                             
------                                       ----------------                            --------------                             
Expired                                      May 22 2010  8:31PM                         May 22 2010  8:32PM

What i'm trying to do is if($s.Contains("Expired")) , report failed. Simple...? :( Problem i'm running into is it looks like Contains method is not being loaded as i get an error like this:

Method invocation failed because [System.Object[]] doesn't contain a method named 'Contains'. At line:1 char:12 + $s.Contains <<<< ("Expired") + CategoryInfo : InvalidOperation: (Contains:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound

So, what can i do to stop powershell from unrolling it to string? Actual ps script below -

$s = @(Invoke-Sqlcmd -Query "USE DB
GO
exec Monitor_TEST_ps 'EXPORT_RUN',NULL,20 " `
                            -ServerInstance "testdb002\testdb_002")

if ($s.Contains("Expired"))   

{
Write-Host "Expired found, FAIL."
}
else {
Write-Host "Not found, OK." 
}

© Stack Overflow or respective owner

Related posts about powershell