Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <#
  2. First set $x so that it contains everything in OrigCSV.csv.
  3. Each line of the CSV will be an array element within $x, with "Name" and "Number" properties according to their entry in the CSV.
  4.  
  5. ipcsv is a built-in alias for Import-Csv
  6. #>
  7. $x=ipcsv .OrigCSV.csv;
  8. <#
  9. Next step is to put all the objects in $x through a ForEach-Object loop.
  10.  
  11. % is a built-in alias for ForEach-Object.
  12. #>
  13. $x|%{
  14. <#
  15. Within ForEach-Object, we're starting a For loop.
  16. The loop definition starts with setting a counter, $y, to 1.
  17. Then, if $y is less than or equal to the current line item's "Number" property, the script block will execute.
  18. After the script block executes, it will increment $y by 1 and check the loop condition again.
  19. Once $y becomes greater than the current line item's "Number" property, the For loop will exit.
  20. #>
  21. for($y=1;$y-le$_.Number;$y++)
  22. {
  23. # This next line simply outputs the "Name" property of the current line item.
  24. $_.Name
  25. # 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.
  26. }
  27. # 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.
  28. }|Out-File NewCSV.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement