Using Add-Content to input multiple variables to a csv file will write each variable to the csv in a new row, such as the following:
Code
$name, $dateTime, $task | Add-Content $csv -Force
Results
$name
$dateTime
$task
I would like to loop the above code with new variable values each time but would prefer the variables to input to new columns for results such as the following:
$name $dateTime $task
$name $dateTime $task
$name $dateTime $task
How can I modify my code to input each of the 3 variables into a new column, then on the next pass, input the 3 new values on the next row across columns 1,2 and 3 like the above example?
Thanks
$nameetc?"$name, $dateTime, $task" | Add-Contentto make your variables into a string line of the right kind for your CSV.Export-Csv -Appendbut you'll need to make a PSCustomObject of the right shape, which will only work if the CSV format is exactly what PowerShell wants)Export-CSV. For now you could just"$name $dateTime $task" | Add-Content $csv -Force