安装DbaInstance-ParameterBinding错误



我试图通过将所需参数传递到数组中的命令(splating(来在dbatools模块中运行Install DbaInstance,但这返回了ParameterBindingArgumentTransformationException

代码

#set parameters
$Computer = "server01"
$version = 2019

#get service account credentials
$sacredential = get-credential -Message "sa account"
$EngineCredential = get-credential -Message "Engine"
$AgentCredential = get-credential -Message "Agent"

$config = @{
ComputerName = $Computer
Version = $version
SqlCollation = "Latin1_General_CI_AS"
AuthenticationMode = "Mixed"
Feature = "Engine"
InstancePath = "D:Program FilesMicrosoft SQL Server"
SaCredential = $sacredential
EngineCredential = $EngineCredential
AgentCredential = $AgentCredential
DataPath = "E:Data"
LogPath = "F:Log"
TempPath = "G:TempDB"
BackupPath = "E:Backup"
PerformVolumeMaintenanceTasks = $true
}
$result = Install-DbaInstance $config
$result | Format-Table
if (-not $result.Successful) {
throw "Failed to install SQL Server"
}

错误

Install-DbaInstance : Cannot process argument transformation on parameter 'SqlInstance'. Cannot convert value "System.Collections.Hashtable" to type
"Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]". 
Error: "Cannot convert value "System.Collections.Hashtable" to type "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter". Error: "Failed to interpret input as Instance: System.Collections.Hashtable""

当version是数组中的第一个参数并且有效值为2019时,我还收到了ParameterBindingValidationException。

Install-DbaInstance : Cannot validate argument on parameter 'Version'. The argument "System.Collections.Hashtable" does not belong to the set "2008,2008R2,2012,2014,2016,2017,2019" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.

如果在所有参数都内联的情况下运行Install DbaInstance命令,它可以正常工作。我很难理解为什么参数飞溅会导致这些错误,以及如何解决这些错误。

将我的评论移动到一个答案。发生这种情况的原因是,当您将参数添加到cmdlet时,正确的语法是:

Some-Cmdlet @ParamVariable

在您的情况下,您需要使用:

$result = Install-DbaInstance @config

正如TheMadTechnician所说,当使用哈希表作为splat变量时,splat需要使用@前缀。

关于飞溅

相关内容

  • 没有找到相关文章

最新更新