A lot of the questions around the internet for this specific topic are oriented into BASH for linux, I was wondering if the same thing can be achieved using just PowerShell.
On Bash, one can use:
for line in $(cat file.txt); do echo $line; done
And then bash will loop through each line of file.txt and send it to echo or whatever command you're using.
How can the same thing be achieved on Windows's powershell?
I found that PS has the "Get-Content
" command that works similarly to "cat
", but I couldn't continue from there.
Best Answer
Ok it turns out that it was not that difficult but I'll leave it here for the future people of the internet.
PowerShell has a defined set of Loops, one of them called
ForEach
One can simply do:
Where
[File]
is the file path you're reading from andWhere
[Command]
is the command you're sending each line into.Just as an example: