Function return values to CSV

Hi

How do I get the return values from a function to a csv-file? Next code indicates what I want to do:

[pre]Function New-Array
{
$array = @()

for($i=0;$i -lt 50)
{
$array += some_value
}

return $array
}

New-Array | Export-Csv -Path some_path[/pre]

For the moment I don’t get the right values, but the number 10 on each row. The number of rows is correct.

The proper way to create such a function would be this:

Function New-Array {
    $array = for ($i = 0; $i -lt 50; $i++) {
        $i
    }
    return $array
}

or even simpler like this:

Function New-Array {
    for ($i = 0; $i -lt 50; $i++) {
        $i
    }
}

But actually you don’t need a function to create an array of increasing numbers. This would work as well:

1..50

Olaf, the real function creates passwords and set it to the users. I need to return the array to a csv for distributing the password to the new users.

I have adopted my function to your first example as suggested:

[pre]$array = for …[/pre]

Still I get the next return instead of the passwords:

[pre]#TYPE System.String
“Length”
“10”
“10”
“10”
“10”
“10”
“10”[/pre]

It’s solved. At the top of the function, I define my parameters and there stood the following:

[pre][Outputtype([int])[/pre]

I changed it to:

[pre][Outputtype([System.Object])][/pre]

Now it works.