我知道这个问题以前在这里和这里都被问过。但出于这样或那样的原因,它对我们来说并不真正有效
所需结果
2个可与Pester参数ParameterFilter
一起使用的脚本块,其中仅扩展变量$testTable
:
{
($Query -like "*SELECT * FROM tableOne*
WHERE TicketNr IS NOT NULL AND TicketCloseDate IS NULL*")
}
{
($Query -like "*SELECT * FROM tableWto*
WHERE TicketNr IS NOT NULL AND TicketCloseDate IS NULL*")
}
下面的代码不起作用,因为我们需要转义$testQuery
中的所有内容。难道没有办法只扩展$testTable
而不扩展其他部分吗?
foreach ($testTable in @('tableOne', 'tableTwo')) {
$testQuery = "*SELECT * FROM $testTable*
WHERE TicketNr IS NOT NULL AND TicketCloseDate IS NULL*"
[ScriptBlock]::create("`$Query `-like $testQuery")
}
我想我已经想通了:
foreach ($testTable in @('tableOne', 'tableTwo')) {
[ScriptBlock]::create(@"
(`$Query -like "*SELECT * FROM $testTable*
WHERE TicketNr IS NOT NULL AND TicketCloseDate IS NULL*" )
"@)
}