Hey Arne,
I found this on techtarget.com, perhaps you should try %* instead ?
% (variable)
A variable is a replaceable parameter. The parameters %0 and %1 to %9 can
be placed anywhere within a batch file. When the batch file is run, %0 is
replaced by the name of the batch file, and the argument variables %1 to
%9 are replaced by the corresponding parameters entered on the command line.
For example, to copy the contents of one folder to another, you would add
the following statement in your batch file:
xcopy %1\*.* %2
When you run the file, you would type the following:
mybatch.bat C:\afolder D:\bfolder.
The effect is the same as if you had written xcopy C:\afolder \*.* D:\bfolder
in the batch file.
The % parameter expands the batch script argument variables (%0, %1, ...,
%9) as follows:
%* in a batch script is a wildcard reference to all the arguments. For individual
argument variables, the expansion options are explained in the following
tables.
Variable Description
%~1 expands %1 and removes any surrounding quotes (")
%~f1 expands %1 to a fully qualified path name
%~d1 expands %1 to a drive letter
%~p1 expands %1 to a path
%~n1 expands %1 to a file name
%~x1 expands %1 to a file extension
%~s1 expanded path contains short names only
%~a1 expands %1 to file attributes
%~t1 expands %1 to date/time of file
%~z1 expands %1 to size of file
%~$PATH:1 searches the directories listed in the PATH environment variable
and expands %1 to the fully qualified name of the first one found. If the
environment variable name is not defined or the file is not found by the
search, then this modifier expands to the empty string.
The modifiers can be combined to get compound results:
Variable Description
%~dp1 expands %1 to a drive letter and path
%~nx1 expands %1 to a file name and extension
%~dp$PATH:1 searches the directories listed in the PATH environment variable
for %1 and expands to the drive letter and path of the first one found
%~ftza1 expands %1 to a dir-like output line
In the above examples %1 and PATH can be replaced by other valid values.
The %~ syntax must be terminated by a valid argument number. The %~ modifiers
may not be used with %*.
Best Regards,
Jacob Saaby Nielsen
http://www.pipforhelvede.net
gmail: jacob DOT saaby
hotmail (IM/LinkedIN/Facebook): same as gmail
> On 22 Jan., 11:55, Jacob Saaby Nielsen <jacob.sa...@xxxxxx>
> wrote:
>
>> Hey Arne,
>>
>> it's completely normal for the arguments to be split at the space
>> character. It's the way powershell interprets arguments.
>>
>> Can you provide an example of what it is you're seeing in the $args
>> array,
>> and
>> what it is specifically you're trying to pass to the script ? > Hi Jacob,
>
> just as simple as:
>
> place a testArguments.ps1 files in the search path. the script
> testArguments.ps1 just echoes its parameters line by line:
>
> # testArguments.ps1
> foreach ($arg in $args) {
> echo $arg
> }
> open up powershell and type
>
> testArguments "1 2" 3
>
> you'll get
>
> 1 2
> 3
> So "1 2" was interpreted as one argument as it should.
> Then try some of the valid variants to start powershell with a
> commandline from Windows Explorer, f.x.
> powershell.exe -noexit -command testArguments "1 2" 3
>
> I get
>
> 1
> 2
> 3
> That's my problem.
>
> Arne
>