我正在尝试从 PowerShell 脚本调用 SQLCMD,但 Powershell 似乎不喜欢我如何将 -InputFile 传递给 Invoke-Sqlcmd。我的代码看起来像这样:
$files = Get-ChildItem -Path $PSScriptRoot -Recurse | Where-Object { $_.Name -match $regex};
Invoke-Sqlcmd -InputFile $files[0].FullName
$files 永远不会为空,因为打印 $files[0].FullName 会输出类似“D:\foo\foo.sql”的字符串。当我的应用程序到达这一行时,它会抛出一个错误,指向我使用 Invoke-Sqlcmd 和“$files”中的“$”字符的同一行。
我收到这两条错误消息:
Invoke-Sqlcmd : The pipeline has been stopped.
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], PipelineStoppedException
+ FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Invoke-Sqlcmd : An expression of non-boolean type specified in a context where a condition is expected
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
+ FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
我如何提供要运行的脚本的文件路径有问题吗?什么是正确的格式。我也尝试使用 .PSPath 而不是 .FullName 但我收到一条错误消息,指出不支持文件路径。