I want to output each line in a text document into its own document where the output documents are named 1.txt, 2.txt, etc. This is my initial code that reads the text documents and outputs the lines one by one.
get-content "artists.txt" | Foreach-Object {$_ | set-content "artists\$counter.txt"}
But as you can imagine, this outputs always to the same document.
I have tried
get-content "artists.txt" |
Foreach-Object {$_ | set-content "artists\$counter.txt" } {$counter++}
as I have seen suggested online and while this increases the counter, it doesn't do what I want (since it still outputs to the same file).
Not really sure where to insert the counter++ here as inside the Foreach-Object loop itself gives me an error (unless I'm inserting it wrong).
Thanks.