7
1
I've been digging in this for a while, but I could not understand how this works. What I need is:
- Be able to run a batch file
- The batch file should have parameters
- The parameters should be passed from the batch file to the PowerShell script that is in the same file
Why I need this? Because I need to run a simple batch file to do some stuff, but I need advanced functionality that works only from PowerShell. Specifically: I need a SaveFileDialog
for some application.
The following is what I have right now, where I stripped the complicated parts of SaveFileDialog
, and left a simple batch + powershell part:
<# :
@echo off
setlocal
powershell -noprofile "iex (${%~f0} | out-string)"
goto :EOF
#>
Write-Host "Hello, I'm PowerShell!"
If I put all this in a batch file, say, myfile.bat
. It runs and calls PowerShell and writes that message.
My question/request: How can I run myfile.bat param1 param2 param3
, and get these arguments/parameters be passed to my PowerShell script? I'd really appreciate a minimal example that just prints the parameters through powershell's write-host
.
Please feel free to ask for any more details. Thank you!
Thanks, man! Unfortunately I don't need this currently, but once I do, I'll consider your answer. Thanks again! – The Quantum Physicist – 2017-05-25T07:56:00.613