因此,我有一个用于部署的脚本,其中一些命令直到sqlps运行后才能被识别,通常我会手动执行。我想自动运行该脚本。这是脚本:
$client = Read-Host "Enter Client name"
$date = Get-Date -Format "yymmdd"
$sqlsrvname = Read-Host "Please enter the sql server name"
$deploytype = Read-Host "Is there a server instance? (1) Yes (2) No"
switch($deploytype){
1 {$Instance = Read-Host "Please Enter instance name"
cd -Path $ppath
Invoke-Command .\sqlpatchremote.ps1 -DBServer $sqlsrvname –dbinstance $Instance –client $client –mainline HTFS –datefolder $date –targetenv $sqlsrvname }
2 {cd -Path $ppath
Invoke-Command .\sqlpatchremote.ps1 –dbs $sqlsrvname –client $client –mainline HTFS –datefolder $date –targetenv $sqlsrvname }
default {"Invalid Selection"}
}
当我尝试运行此脚本时,出现以下错误:
Invoke-Command : A parameter cannot be found that matches parameter name 'DBServer'.
At line:17 char:38
+ Invoke-Command .\sqlpatchremote.ps1 -DBServer $sqlsrvname –dbinstance $Instance
...
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindi
ngException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.
InvokeCommandCommand
当我手动键入此命令时,它告诉我它无效的命令在正常工作时,该如何工作?假定此脚本用于在SQL Server上安装SQL数据库。当我手动运行此代码时,只需键入“ sqlps”,然后导航到脚本目录。然后,我使用填充的参数运行它,但它没有给我错误。我觉得这可能是使它正常工作的简单解决方案,但我不确定它是什么,也不确定如何提出要求。谢谢!
错误:
Invoke-Command : A parameter cannot be found that matches parameter name 'DBServer'.
At line:17 char:38
Invoke-Command
拒绝参数DBServer
。这意味着您要将参数传递给Invoke-Command
而不是脚本。
要将参数传递给要调用的脚本,必须使用-ArgumentList
参数。
尝试 :
Invoke-Command -ComputerName "targethost" .\sqlpatchremote.ps1 -ArgumentList "-DBServer $sqlsrvname –dbinstance $Instance –client $client –mainline HTFS –datefolder $date –targetenv $sqlsrvname"
编辑:真的不确定上述参数的语法:(((如果有人可以确认?)
使用正确顺序的参数,我已经成功地像这样测试了它:
Invoke-Command -ComputerName "targethost" "scriptpath" -ArgumentList $arg1,$arg2#,...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句