我试图在dbatools模块中运行,方法是将所需的参数传递给数组中的命令(splatting),但这将返回一个
代码
#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 Files\Microsoft 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""当版本是数组中的第一个参数时,我还收到了一个ParameterBindingValidationException,其有效值为2019年。
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.如果使用内联的所有参数运行命令,它可以正常工作。我很难理解为什么我要用参数飞溅来获得这些错误,以及如何解决它们。
发布于 2022-07-20 19:18:15
把我的评论移到一个答复上。之所以发生这种情况,是因为当您将参数拆分到cmdlet时,正确的语法是:
Some-Cmdlet @ParamVariable在您的情况下,您需要使用:
$result = Install-DbaInstance @config发布于 2022-07-20 19:17:05
正如TheMadTechnician所述,使用散列表作为splat变量时,splatting需要使用@前缀。
https://stackoverflow.com/questions/73056884
复制相似问题