I have a Commands.csv file like:
| Command |
| -----------------------------------------------|
|(Get-FileHash C:\Users\UserA\Desktop\File1).Hash|
|(Get-FileHash C:\Users\UserA\Desktop\File2).Hash|
|(Get-FileHash C:\Users\UserA\Desktop\File3).Hash|
Header name is "Command"
My idea is to:
- Use
ForEach ($line in Get-Content C:\Users\UserA\Desktop\Commands.csv ) {echo $line} - Execute $line one by one via powershell.exe, then output a result to a new .csv file - "result.csv"
Can you give me some directions and suggestions to implement this idea? Thanks!
Import-Csv path | % { & $_.Command }Commandor, if your file lacks a header row, use the-Headerparameter to declare a single column header:Import-Csv <path> -Header Command. It would be a good idea to edit your question and put your sample data in a code block rather than a table -- it's not obvious if "Commands" is the first row or not.&, when given a string, only supports command names / paths, not full commands.