Writing a PowerShell function from scratch for once (rather than squinting at someone else's), and it misbehaves in a way I can't explain. It's meant to hand back one path. It hands back an array.
function Get-ReportPath {
$names = [System.Collections.ArrayList]::new()
foreach ($f in Get-ChildItem -Filter *.xlsx) {
$names.Add($f.Name)
}
Write-Verbose "found $($names.Count) workbooks"
Join-Path $PWD 'report.xlsx'
}
$path = Get-ReportPath
$path.GetType().Name # Object[]
With three workbooks in the folder, $path holds four things. The last is the path I wanted. The first three are 0, 1 and 2 (which looked like a counter I never wrote, and I stared at it for a good while). Where do those numbers come from, and what's the usual way to stop a helper list leaking into the result?