How to store "function with a dynamic name" result into variable with dynamic name

I have a function 
get-something$($dynamicNumber){
}

Now, I need to run this function and store result into dynamic variable

I tried to use new-variable below with some variations but no luck

new-variable DynamicVariableName$(number) -value get-something$($dynamicnumber)

Any ideas?

Hmmm … your “setup” seems to me very unusual. Could you explain what your general requirement is? Maybe there is a better way of achieving it.

Hm, not easy to explain. In general, we need to run the same function (we cover limited scope of data each time as the system we are storing results in is limited so we need to run it several times to cover all data
e.g first run would be function1 which results should be stored in $varfunction1 (data from 1 - 20)
than function2 which results should be stored in $varfunction2 etc (data from 20-40)

Not sure if that makes sense?

Actually not that much unfortunately. Does function2 do something different to function1? If not why have different functions then? Wouldn’t be enough to provide different parameter values to cover different data sets? And what do you do with the different variables you want to store the results in? I could imagine that it’s going to be hard to use dynamic variables for further steps.

Could you elaborate a little more detailed?

e.g. We have 100 users
We need to collect username/date created/ data used etc… about all users and store them in a table that can accept only 10 user’s info in 1 table. That is why we need to run it 10 times.
We need to keep function results to a separate variables as there is no way to submit data to 1 table until we collect data for all 100 users (may sound weird but that is how it works)

Function code is the same, we just run the same code for different set of users (we can’t run code for different users within the same function, it has to be run as a separate function. That is why we need dynamic name for functions as well)

Makes sense now?

Nope. Sorry, I’m still not buying it. :wink: You claim it but you do not explain it. It is a quite easy task to output a given list of elements in chunks of a certain size … for example:

$ProcessList = Get-Process
for ($i = 0; $i -lt $ProcessList.Count; $i+=10) {
    "Processes from #$i to #$($i + 9)"
    $ProcessList[$i..($i + 9)]
}

On my system I have about 320 processes running. Following your logic I would have to create 32 separate functions doing actually the same work to get the same result like I got with just 2 or 3 lines of code.

Not really. Whole html structure is tied to a function (generated) and that is why we can’t run it inside one function. Anyway, I just figured out that I don’t have to use dynamic (different) name for functions, just different variable where we store function results and that resolve my problem. Thanks Olaf for always willing to help

e.g.

$FunctionResult = myfunction
          
New-Variable "$SetOfData$($setOfDataNum)" -Value $functionResult -Force

Hmmm … I’d expect even that should be solvable with an array of arrays or a multi (two) dimensional array. But anyway … great that you’ve got a little bit further. :+1:t4: :wink: :slightly_smiling_face: