Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- First set $x so that it contains everything in OrigCSV.csv.
- Each line of the CSV will be an array element within $x, with "Name" and "Number" properties according to their entry in the CSV.
- ipcsv is a built-in alias for Import-Csv
- #>
- $x=ipcsv .OrigCSV.csv;
- <#
- Next step is to put all the objects in $x through a ForEach-Object loop.
- % is a built-in alias for ForEach-Object.
- #>
- $x|%{
- <#
- Within ForEach-Object, we're starting a For loop.
- The loop definition starts with setting a counter, $y, to 1.
- Then, if $y is less than or equal to the current line item's "Number" property, the script block will execute.
- After the script block executes, it will increment $y by 1 and check the loop condition again.
- Once $y becomes greater than the current line item's "Number" property, the For loop will exit.
- #>
- for($y=1;$y-le$_.Number;$y++)
- {
- # This next line simply outputs the "Name" property of the current line item.
- $_.Name
- # After the For loop exits, the script will return to the ForEach-Object loop and proceed to put the next item into the For loop.
- }
- # After ForEach-Object is done with its work, we pipe the output to Out-File so that the list gets written to a new CSV file.
- }|Out-File NewCSV.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement