You can use:
$file = get-content data.csv
$group = @()
$name = @()
foreach($line in $file){
$line = $line -split ","
$group += $line[0]
$name += $line[1]
}
$name > name.txt
$group > group.txt
# Use ">>" if name or group.txt already exist
This will take every line in the file and split it up using , as a delimiter then assign the first value into the $group array and the same with $name
Tested with exact csv file, working powershell version 5.1.18362.752
Update: If you want to pass the array line by line, you can use:
$file = get-content data.csv
$group = @()
$name = @()
foreach($line in $file){
$line = $line -split ","
$group += $line[0]
$name += $line[1]
}
for($i=0;$i -lt group.length;$i++){
$group[$i] >> group.txt
}
for($i=0;$i -lt name.length;$i++){
$name[$i] >> name.txt
}
With the added for loop, it passes the arrays line by line
Import-Csv -Path 'data.csv' -Header Group, Name | ForEach-Object { $group = $_.Group ; $name = $_.Name; <# Do what needs to be done with these variabes #> }??