"fixitchris" <fixitchris@discussions.microsoft.com> wrote in message
news:59E30274-C68A-4188-9BF1-12017E19F085@microsoft.com...
> oy.... so simple
>
> "select * from isalogger where [desthost] like '%$host_%'"
If I understand this correctly, you've actually found a way to do this -
although it looks like what you show would turn into just
select * from isalogger where [desthost] like '%%'
If a string value seems to have problems, I just stuff it into a variable
and then echo it to see how it is actually rendered by PS. In your case, it
would work out like this assuming that $host_ contains the value
192.168.1.250:
PS> $query = "select * from isalogger where [desthost] like '*$host_*'"
PS> $query
select * from isalogger where [desthost] like '*192.168.1.250*'
====
Here's where your original statement went wrong, in case you didn't figure
out the details. You were using this query:
"select * from isalogger where [desthost] like '*$('($host_)')*'"
Since the string starts with a doublequote, everything inside it is treated
as if double-quoted until a closing double-quote is encountered. So
PowerShell treats everything as literal values up to the first $. When it
sees a $, it tries to find the nested variable/expression and evaluate it.
At this point, we've already treated this first bit as a literal string:
select * from isalogger where [desthost] like '*
and PowerShell sees the following as a parenthesized term to evaluate:
$('($host_)')
In other words, it is trying to evaluate this:
'($host_)'
Since that's a single-quoted string, it's just itself, and PowerShell
returns this as the literal value:
($host_)
You tack on the terminal *' and get:
select * from isalogger where [desthost] like '*($host_)*'
as your expression.