Search code examples
powershellbatch-filecmd

passing CMD arguments to Powershell


Here the Code :

@echo off
if "%*"=="" (echo Give me the URL! && exit /b)
echo Output :
set /p output=
powershell Invoke-WebRequest -Uri %* -OutFile output

The problem in this code I've written is output variable
how to send that variable into powershell ?


Solution

  • Use %output% to expand the output variable - and remember to quote the arguments (otherwise it'll break if someone inputs a path with spaces):

    @echo off
    if "%*"=="" (echo Give me the URL! && exit /b)
    echo Output :
    set /p output=
    powershell Invoke-WebRequest -Uri '%*' -OutFile '%output%'