我正在从另一个脚本中调用这样的 powershell 脚本。
function test_execute_sql_2_direct_query()
{
& C:\Server\Scripts\PowerShellDeploy\Execute-SQL-Command.ps1 -SERVER_NAME "myserver" -SQL_COMMAND_TYPE "input" -SQL_FILE ".\select.sql" -USER_NAME "username" -PASSWORD "password" -DATABASE "accounts"
}
当我调用该函数时,我从 Powershell 收到一条错误消息,上面写着“无法验证参数“查询”上的参数。参数为空或空......'
我不太明白为什么我会收到这条消息?Execute-SQL-Command 脚本没有名为“Query”的参数。很可能我错过了一些东西。
这是它的参数部分:
param(
[Parameter(
HelpMessage="Server Name")]
[string]$SERVER_NAME = "",
[Parameter(
HelpMessage="Database")]
[string]$DATABASE = "",
[Parameter(
HelpMessage="Path to .SQL File to run. Used in input file mode (not direct query mode)")]
[string]$SQL_FILE ="",
[Parameter(
HelpMessage="Server Port (default = 1433)")]
[string]$SERVER_PORT = "1433",
[Parameter(
HelpMessage="Server Transport (default = tcp")]
[string]$TRANSPORT = "tcp",
[Parameter(
HelpMessage="Method of connecting to database <passthrough, credentialed>")]
[string]$CONNECT_METHOD = "passthrough",
[Parameter(
HelpMessage="Username -- used only for credentialed login")]
[string]$USER_NAME = "username",
[Parameter(
HelpMessage="Command type-- direct query or input file (.sql)")]
[string]$SQL_COMMAND_TYPE = "DIRECT_QUERY",
[Parameter(
HelpMessage="SQL statement text type-- used in direct queries")]
[string]$SQL_STATEMENT = "",
[Parameter(
HelpMessage="Password -- used only for credentialed login")]
[string]$PASSWORD = "pwd")