Decent technique for creating string array with same value?

For the Start-BitsTransfer cmdlet, assuming I have a $sourcepaths array and my destination is a single directory, is this a decent technique?

$destarray = [System.Collections.ArrayList]::Repeat('C:\TEMP\',$sourcepaths.count)

This is cool :+1:, didn’t know about Repeat() method.

Yep, this will get you basically the same result as other methods in PowerShell would. Nice find, I hadn’t known about this one either! :slight_smile:

Possible alternate methods:

$destArray = (1..$sourcePaths.Count).ForEach{ "C:\TEMP" }
$destArray = foreach ($N in 1..$sourcePaths.Count) { "C:\Temp" }

Both of those will get you a standard array back, instead of an arraylist, however; so if you need the arraylist at the other end, use ::Repeat()

That said, ArrayList is effectively deprecated, so I would recommend using List[PSObject] instead… although that initial list may need to be created via a LINQ enumerable expression first, as it seems List<T> lacks the .Repeat() method itself.