I have a script with which I'm collecting data about users like this:
$testObject = [PSCustomObject]@{
username = $username
name = $name
}
Next, I'm getting more info and add to testObject like this:
$testObject | Add-Member address address
At the end I'm exporting it to csv:
$testObject | Export-Csv -Path "output.csv" -NoTypeInformation
I need to change the script so the creation of the testObject is in a loop since I will run it for a list of users. How can I write this to create a new csv when the script starts, but append all new objects?
I'm trying to avoid creating an array of PSCustomObject since I'm using the script on large amount of data and I would prefer to write one object at a time to the csv.