PowerShell变量未在字符串中展开?

PowerShell变量未在字符串中展开?,powershell,Powershell,我写了一些PowerShell param ( [Parameter(Mandatory=$true)][string]$company, [Parameter(Mandatory=$true)][string]$output ) ... $objRecordset.Open("Select Col1, Col2, Col3 From $company_Table1.DBF", $objConnection,$adOpenStatic,$adLockOptimistic)

我写了一些PowerShell

param (
    [Parameter(Mandatory=$true)][string]$company,
    [Parameter(Mandatory=$true)][string]$output
)

...

$objRecordset.Open("Select Col1, Col2, Col3 From $company_Table1.DBF", $objConnection,$adOpenStatic,$adLockOptimistic)
我正在使用

.\Test.ps1 -company A -output C:\test.txt
但是由于某种原因,
$company
变量即使在“引号”中也没有被扩展


当我将其硬编码为
A_Table1.dbf时,它工作正常…

错误消息告诉您PowerShell正在解析
$company_Table1
作为变量名称<代码>.
不充当分隔符

您需要使用大括号
{}

${company}_Table1.DBF

.DBF代表数据库文件。 您正在尝试对数据库而不是该数据库中的表进行选择。 所以这是有道理的,它不起作用

它应该是从TBL_中选择*无论限制为0,1


因此,您首先需要打开到DB文件本身的连接,然后根据该DB中的表进行选择。

当然,天哪。谢谢一旦允许,我会接受。我会想象ISE会将
$company\u Table1
显示为单个变量。很难忽略这一点。还有一种常见的做法是将变量包装到一个新的块中,如下所示
“从$($company)\u Table1.DBF中选择Col1、Col2、Col3”
@rohindhart,他提到了ISE。可能重复
${company}_Table1.DBF