<?xml version="1.0" encoding="windows-1252"?>
<node id="938888" title="Re: How do you pass arguments from Perl to Powershell?" created="2011-11-18 12:26:30" updated="2011-11-18 12:26:30">
<type id="11">
note</type>
<author id="154438">
Util</author>
<data>
<field name="doctext">
&lt;p&gt;
First, basic debugging:
Extract that long command string to a separate var, and print it.
&lt;code&gt;
my $cmdline = 
'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -command "&amp; D:\scripts\get-info.ps1 "."\'$val1\' "."\'$filename\'"';

print $cmdline, "\n";

Win32::Process::Create(
    $process,
    $^X,
    $cmdline,
    0,
    DETACHED_PROCESS,
    ".",
);
&lt;/code&gt;
You will see that you are not passing the string that you think. When you put a $var in single quotes, it does not get replaced with the value of $var (interpolation). Double-quoted strings *do* interpolate.
&lt;/p&gt;

&lt;p&gt;
Second, (as [id://961] pointed out), &lt;code&gt;$^X&lt;/code&gt; is the wrong thing to pass as second parameter; it would run another copy of Perl, instead of PowerShell. Read the docs, not just example code. The [mod://Win32::Process] docs say that it is the "full path of the executable module", so in your case, it is probably the full path to PowerShell.
&lt;/p&gt;

&lt;p&gt;
When quoting is complex, it helps to build the string in stages, and sometimes to use &lt;code&gt;q{...}&lt;/code&gt; and &lt;code&gt;qq{...}&lt;/code&gt; in place of &lt;code&gt;'...'&lt;/code&gt; and &lt;code&gt;"..."&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
Use &lt;code&gt;0&lt;/code&gt; instead of &lt;code&gt;DETACHED_PROCESS&lt;/code&gt; until everything else is working right, so you can better see the errors from PowerShell.
&lt;/p&gt;
&lt;p&gt;
The code below is untested for PowerShell, since I lack it on my Win2k box. I don't know exactly what kind of quoting it expects, or what that &lt;code&gt;&amp;&lt;/code&gt; does, but this should get you farther down the path:
&lt;code&gt;
use strict;
use warnings;
use Win32::Process;

my $val1     = 'dummy1';
my $filename = 'dummy2';

my $q_val1     = "'" . $val1     . "'";
my $q_filename = "'" . $filename . "'";

my $appname =
    'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe';

my $ps_command = join ' ', (
    '&amp;',  'D:\scripts\get-info.ps1', $q_val1, $q_filename,
)

my $cmdline = qq{$appname -command "$ps_command"};

print $cmdline, "\n";

my $process;
my $rc = Win32::Process::Create(
    $process,
    $appname,
    $cmdline,
    0,
    0, # replace with DETACHED_PROCESS later
    ".",
);

if ( $rc == 0 ) {
    print Win32::FormatMessage( Win32::GetLastError() );
}
else {
    print "Success!\n";
}
&lt;/code&gt;
&lt;/p&gt;
</field>
<field name="root_node">
938872</field>
<field name="parent_node">
938872</field>
</data>
</node>
