Home > OS >  passing CMD arguments to Powershell
passing CMD arguments to Powershell

Time:11-29

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 ?

CodePudding user response:

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%'
  • Related