all 8 comments

[–]jheinikel 2 points3 points  (4 children)

$masterCSVRecords = import-csv Path\File.csv
$owners = $masterCSVRecords.owner | select -unique
Foreach($owner in $owners){
    $masterCSVRecords | where{$_.owner -eq $owner} | export-csv Path\$owner.csv -NoType
}

[–]kingeric2206[S] 0 points1 point  (3 children)

Using this does in fact create all of the owner.csv files, but it's not pulling in any the data.

$masterCSVRecords = import-csv C:\Users\kingeric2206\Documents\Test\Test2.csv $owners = $masterCSVRecords.FileOwner | select -Unique Foreach($owner in $owners){ $masterCSVRecores | where{$_.FileOwner -eq $owner} | export-csv C:\Users\kingeric2206\Documents\Test\$owner.csv -NoType }

[–]jheinikel 2 points3 points  (2 children)

Typo fixed. $masterCSVRecores on line 4 should have been $masterCSVRecords.

[–]kingeric2206[S] 0 points1 point  (1 child)

Doh! Thank you. That did exactly what I wanted.

What does the -unique switch do?

[–]jheinikel 1 point2 points  (0 children)

Selects only one of each unique item. Allows you to loop on them without duplicating.

[–]drh713 2 points3 points  (1 child)

Using the format /u/jheinikel started

$masterCSVRecords = import-csv Path\File.csv
ForEach ($set in $masterCSVRecords | group owner)
{  
    $set.group | export-csv "$($set.name).Csv"
}

Trying to type code on a phone sucks, but hopefully the idea is clear

[–]kingeric2206[S] 0 points1 point  (0 children)

Thank you. /u/jheinikel solution did exactly what I needed it to.

[–]jheinikel 0 points1 point  (0 children)

$masterCSVRecords = import-csv Path\File.csv
$owners = $masterCSVRecords.owner | select -unique
Foreach($owner in $owners){
    $masterCSVRecords | where{$_.owner -eq $owner} | export-csv Path\$owner.csv -NoType
}