I have a powershell script that runs an invokesqlcmd statement and counts the number of lines in the return and creates a variable based on that number. It should only close out if there are one or two rows, depending on if there are errors returned (some errors are expected) but a couple of times it has closed while there were still three rows. I want it to close, and it normally does if the only values are "Successful" and "Failure" but it has closed out with a 3rd value of "Processing".
Here is the relevant part of the script.
$var = invoke-sqlcmd -ServerInstance "$server" -database "$db" -inputfile "C:\updated-selectstatus.sql" |measure-object -line|select-object -expandproperty lines
while ($var -ge 1)
{
$var = invoke-sqlcmd -ServerInstance "$server" -database "$db" inputfile "$updated-selectstatus.sql" |measure-object -line|select-object -expandproperty lines
clear-host
invoke-sqlcmd -ServerInstance "$server" -database "$db" -inputfile "$updated-selectstatus.sql"
Start-Sleep -Seconds 5
if ($var -eq 2){
if ((invoke-sqlcmd -ServerInstance "$server" -database "$db" -inputfile "$updated-selectstatus.sql"|select-object -expandproperty statusname|select-string -simplematch successful) -and (invoke-sqlcmd -ServerInstance "$server" -database "$db" -inputfile "$updated-selectstatus.sql"|select-object -expandproperty statusname|select-string -simplematch failure)) {invoke-sqlcmd -ServerInstance "$server" -database "$db" -inputfile "$updated-selectstatus.sql"|out-gridview; break}
}
if ($var -eq 1){
if ((invoke-sqlcmd -ServerInstance "$server" -database "$db" -inputfile "$updated-selectstatus.sql"|select-object -expandproperty statusname|select-string -simplematch successful) -or (invoke-sqlcmd -ServerInstance "$server" -database "$db" -inputfile "$updated-selectstatus.sql"|select-object -expandproperty statusname|select-string -simplematch failure)) {invoke-sqlcmd -ServerInstance "$server" -database "$db" -inputfile "$updated-selectstatus.sql"|out-gridview; break}
}
}
Have I somehow jumbled up my test logic conditions?