Powershell: Text Search In A Table Value

Shane O’Neill clarifies a misunderstanding in Powershell:

and you are running the following PowerShell command to check if the results contain a value…

$String = "abc"
$Array = @(Invoke-Sqlcmd -ServerInstance "SQLServer" -Database "Database" -Query "SELECT code FROM dbo.users")

It will return FALSE.

Now we know that the FALSE is false because we know that the string is in there!
This code is proven to work with arrays as stated here by the “Hey, Scripting Guy!”s so this was getting filed under “WTF PowerShell”

It’s a good post, so check it out and remember that DataRows aren’t strings.

Related Posts

Watch Those Powershell Shell Versions

Emin Atac reviews a couple of 64- versus 32-bit Powershell oddities: Context My colleagues send an message with a link that points to a script located on a shared drive to help our users reinstall their software. Our users just click on the link in their Outlook and got a message saying: \\servername.fqdn\share\softwarename\install.ps1 cannot be […]

Read More

Simplified Disaster Recovery With dbatools

Chrissy LeMaire shows how you can make DR a lot easier with dbatools: When we talk about Disaster Recovery or DR, it’s often coupled with the term High Availability or HA. Here are some definitions from my graduate course on HADR. high availability Deals with minor outages, and failover solutions are automated The goal is to restore full […]

Read More


August 2017
« Jul Sep »