Powershell – Load Arguments from a file


This is my 2nd question is fairly quick succession! Essentially at the moment, I’m running a powershell script which I execute manually and pass arguments to on the CMD line like:

Those are placed into variables and used in the script.

Is there a way I could add these line by line to a text file such like:

And then get the Powershell script to use the first line, do the script, then loop back and use the next line, do the script, loop back and so on.

So in context – I need to mount images in the following naming context


So in my text file:

And so on. It uses this information to mount a specific backup image (via ShadowProtect’s



You can try do something like this:

content of p.txt:

the content of the script p.ps1

the call to script:

the result:


after your edit you can try something like this.


Powershell – Load Arguments from a file by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply