I am trying to figure out how to populate an unknown number of variables based on user input (writing a script that obtains certificates from a CA, and sometimes these certificates contain more than one name (SANs) and it is impossible to know how many so this needs to be dynamic).
I know I start with setting up params like this:
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string[]]$SANs
)
And then I need to somehow take those values and assign them to $san1, $san2, $san3 and so on.
Being new to programming, I am not even sure what to call this. Would you use a foreach loop to somehow populate these variables?
ForEach ($SAN in $SANs) {
what do I do here?
}
The end result is a need to populate a string with these variables like dns=$san1&dns=$san2&dns=$san3 etc...
$SANin yourforeachwould act as each individual item. Ex: Inside yourforeachputWrite-Host $SANthis will hopefully give you a better understanding on what is going on.'dns=' + ($SANs -join 'dns=')right?$SANvariable right inline with the text (I'm making an output text/inf file that will be used to generate the request). Like this:_continue_ = "dns=$SAN"r`&is missing from the'dns=' + ($SANs -join '&dns=');-)