Powershell function that creates a array by input
- by user2971548
I'm quite new to Powershell and working on a little project with functions.
What I'm trying to do is creating a function that takes 2 arguments.
The first argument ($Item1) decides the size of the array, the second argument ($Item2) decides the value of the indexes.
So if I write: $addToArray 10 5
I need the function to create a array with 10 indexes and the value 5 in each of them. The second argument would also have to take "text" as a value.
This is my code so far.
$testArray = @();
$indexSize = 0;
function addToArray($Item1, $Item2)
{
while ($indexSize -ne $Item1)
{
$indexSize ++;
}
Write-host "###";
while ($Item2 -ne $indexSize)
{
$script:testArray += $Item2;
$Item2 ++;
}
}
Any help is appreciated.
Kind regards
Dennis Berntsson