url - Powershell Parameters -



url - Powershell Parameters -

i extreme newbie powershell. have script want pass url parameter. url runs php process creates , downloads pdf file script prints pdf , deletes pdf. cannot url parm work.

below script

$w=$args[0] start $w $directory = "c:\users\pslessor\downloads\" get-childitem -path $directory -recurse -include *.pdf | foreach-object {start-process -filepath $_.fullname -verb print -passthru | %{sleep 5;$_} | kill } remove-item c:\users\pslessor\downloads\* -include *.pdf

this script beingness executed batch file printpl.bat

set thisscriptsdirectory=%~dp0 set powershellscriptpath=%thisscriptsdirectory%printpl.ps1 powershell -noprofile -executionpolicy bypass -command "& '%powershellscriptpath%' %1";

and testing testprint.bat

c:\wget\printpl "https://partners.wayfair.com/print_shipping_docs.php?print=1&printpackingslips=1&packingslippos=cs287851107"

the url in 1 string editor forcing line feed @ .php?

the error getting string starting:

at line:1 char:25 + & 'c:\wget\printpl.ps1' <<<< 'https://partners.wayfair.com/print_shipping_docs.php?print; missing terminator: '. @ line:1 char:85 + & 'c:\wget\printpl.psl' 'https://partners.wayfair.com/print_shipping_docs.php ?print; <<<< + categoryinfo :parsererror: <https://partner...docs.php?print;: string> [], parentcontainserrorrecordexception + fullyqualifiederrorid : terminatorexpectedatendofstring 'printpackingslips' not recognaized internal or external command, operable programme or batch file. 'packingslippos' not recognized internal or external command, operable programme or batch file

this happening because when pass arguments command interpreter expands variables , see this:

powershell -noprofile -executionpolicy bypass -command "& 'c:\wget\printpl.ps1' https://partners.wayfair.com/print_shipping_docs.php? print=1&printpackingslips=1&packingslippos=cs287851107"

so command trying execute c:\wget\printpl.ps1, , assumes comes next arguments. since passed has space, , not enclosed in quotes or double quotes assumes multiple arguments. sees as:

execute script: c:\wget\printpl.ps1 next arguments:

$args[0]=? $args[1]=print=1&printpackingslips=1&packingslippos=cs287851107

to stop happening need enclose url in quotes well, command should this:

powershell -noprofile -executionpolicy bypass -command "& '%powershellscriptpath%' '%1'"

edit: ok, didn't work case. we're going alter little bit. instead of -command i'm going suggest utilize -file. powershell execution line within batch file this:

powershell -noprofile -executionpolicy bypass -file "%powershellscriptpath%" %*

you should able run batch file had been. i'm confident work you.

url powershell escaping character

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -