I have some pseudo code similar to the below
$funcValues = @(New-Object -TypeName psobject -Property @{'Function' = ''; 'Value' = '';})
function func1(){
while($i -lt 5){
$funcValues += @(New-Object -TypeName psobject -Property @{'Function' = 'func1'; 'Value' = $i;})
$i++
}
}
function func2(){
while($i -lt 3){
$funcValues += @(New-Object -TypeName psobject -Property @{'Function' = 'func2'; 'Value' = $i;})
$i++
}
}
func1
func2
$funcValues | Export-CSV C:\path\results.csv -noType
The goal is to have both functions add to the array and after calling the functions export the array to a csv. However when this code is inside a function, it doesn't write anything to the array, but if the code is outside a function, it works.
I'm guessing this has to do with variable scoping, but I'm very unfamiliar with how scoping works in powershell.