I am trying to run Install-DbaInstance in dbatools module by passing the required parameters to the command in an array (splatting), but this is returning an ParameterBindingArgumentTransformationException
Code
#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"
}
Error
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""
I have also received an ParameterBindingValidationException when version was the first parameter in the array and has a valid value of 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.
If run the Install-DbaInstance command with all the parameters inline it works fine. I am struggling to understand why I am getting these errors with parameter splatting and how to resolve them.
Moving my comment to an answer. This happened because when you splat parameter to a cmdlet the correct syntax is:
Some-Cmdlet @ParamVariable
In your case you would need to use:
$result = Install-DbaInstance @config