1

I am calling the dbatools Install-DbaInstance function, and one of the parameters is Feature. I initialize the variable to "Engine". If $bolSSIS -eq $true, I want to add "IntegrationServices" to the variable. If $bolSSAS -eq $true, I want to add "AnalysisServices" to the variable.

The code below is not complete, but I believe is enough to explain what I'm trying to do:

$bolSSIS = $true
$bolSSAS = $false
$InstallFeatures = "Engine"
if ($bolInstallFeatureSSIS -eq $true) { $InstallFeatures += ",IntegrationServices" }
if ($bolInstallFeatureSSAS -eq $true) { $InstallFeatures += ",AnalysisServices" }

Install-DbaInstance -Feature $InstallFeatures

The code above returns the error: Cannot validate argument on parameter 'Feature'. The argument "Engine,IntegrationServices" does not belong to the set "Default,All,Engine,Tools,Replication,FullText,DataQuality,PolyBase,MachineLearning,AnalysisServices,IntegrationServices, {others removed for brevity} " specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.

Here's my question: How do I set $InstallFeatures?

I've tried strings, arrays, hashes, and other variable types.

FWIW, if $InstallFeatures is set to only "Default", the Install-DbaInstance -Feature $InstallFeatures command works and does not return an error.

wmeitzen
  • 90
  • 11

2 Answers2

2

If you declare $InstallFeatures as an array, adding more strings will add them as array elements rather than concatenating.

e.g

$boolSSIS = $true
$boolSSAS = $false
$InstallFeatures = @("Engine")
if ($boolSSIS) { $InstallFeatures += "IntegrationServices" }
if ($boolSSAS) { $InstallFeatures += "AnalysisServices" }
OwlsSleeping
  • 1,487
  • 2
  • 11
  • 19
2

Parameter Feature is defined as string array ([string[]]$Feature). You are sending a single string where it should be an array.

Without changing the rest of your script, you could do

Install-DbaInstance -Feature ($InstallFeatures -split ',')
Theo
  • 57,719
  • 8
  • 24
  • 41