1

I upgraded our PS version to 3.0 and some of our scripts stopped working. After a lot of debugging I realized there is an issue with the Start-Process command.

Basically, when I run the Start-Process directly in the PowerShell cmd it does run the program with the correct arguments. However, when I run the script, it won't give any error but the program will not run.

The script is a bit long, but this is the way I can test the snippet that's failing.

$SERVER = 'servername'  
$PORT = 'xxxx' 
$TPath = 'E:\epicor\PowerShell\export\POAutomation\'                        
$User = 'username'
$Psw = 'password'
$Import = 'PO Combined'
$file = $TPath + 'AutomaticPOHeaders.csv' 
$DMTPATH = 'E:\epicor\Epicor905\Client\dmt.exe'


$Param = "-ArgumentList `'-user=`"$User`" -pass=`"$Psw`" -server=$SERVER -port=$PORT -import=`"$Import`" -source=`"$file`" -add=true -update=false -noui=true`'"
Start-Process $DMTPATH $Param -Wait
"Finished"

I even wrote to a log file to check if the $Param string is well formed and if the Start-Process command is also well written. When I copy paste the strings in the log file into the PS command line, they run successfully.

I've been stuck with this more than 4 hours now.

Thanks in advance.

Sandra
  • 175
  • 1
  • 2
  • 11

2 Answers2

0

i dont know what dmt is waiting for but this command runs successfully on ps V3. are you sure about you argumentlist parameter ? and seems to be a mess with your quotes

slight changes : use echoargs.exe instead of DMT and add a switch to not open a new window :

$DMTPATH = 'echoargs.exe'
$Param = "-ArgumentList `'-user=`"$User`" -pass=`"$Psw`" -server=$SERVER -port=$PORT -import=`"$Import`" -source=`"$file`" -add=true -update=false -noui=true`'"
Start-Process -nonewwindow $DMTPATH $Param -Wait
"Finished"

results :

Arg 0 is <-ArgumentList>                                                                                                                                                                     
Arg 1 is <'-user=username>                                                                                                                                                                   
Arg 2 is <-pass=password>                                                                                                                                                                    
Arg 3 is <-server=servername>                                                                                                                                                                
Arg 4 is <-port=xxxx>                                                                                                                                                                        
Arg 5 is <-import=PO Combined>                                                                                                                                                               
Arg 6 is <-source=E:\epicor\PowerShell\export\POAutomation\AutomaticPOHeaders.csv>                                                                                                           
Arg 7 is <-add=true>                                                                                                                                                                         
Arg 8 is <-update=false>                                                                                                                                                                     
Arg 9 is <-noui=true'>                                                                                                                                                                       

Command line:                                                                                                                                                                                
"C:\Windows\EchoArgs.exe" -ArgumentList '-user="username" -pass="password" -server=servername -port=xxxx -import="PO Combined" -source="E:\epicor\PowerShell\export\POAutomation\AutomaticPOH
aders.csv" -add=true -update=false -noui=true'                                                                                                                                               

Finished   

Can you try to start dmt from cmd.exe ? something like :

$p=@("/C";"dmt.exe";"-user'test'" ....)
Start-Process -NoNewWindow cmd.exe $p 
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
  • DMT is an application that will import data into our ERP system. It is waiting because it first needs to import Purchase Order Headers and then it will import their lines separately. I believe the $Param string is correctly formed because the log file I create shows it correctly: Start-Process E:\epicor\Epicor905\Client\dmt.exe -ArgumentList '-user="dmt" -pass="dmtUser" -server=FIESP-MARS -port=9401 -import="PO Combined" -source="E:\epicor\PowerShell\export\POAutomation\AutomaticPOHeaders.csv" -add=true -update=false -noui=true' -Wait. – Sandra Apr 10 '14 at 09:20
  • 1
    If I use the start-process directly in PS command line it works, but when running from the script it doesn't. – Sandra Apr 10 '14 at 09:23
  • how do you invoke your script ? – Loïc MICHEL Apr 10 '14 at 09:29
  • dmt is waiting only one argument ( the argumentlist variable) right ? – Loïc MICHEL Apr 10 '14 at 09:37
  • no, each one of the -xxxx are arguments for dmt. As I said, the script used to work well when we had PS 2.0, now with 3.0 it just doesn't run. – Sandra Apr 10 '14 at 09:56
  • sorry i dont know. As a workarround you could start powershell.exe with the `-version 2` switch – Loïc MICHEL Apr 10 '14 at 09:58
  • I can't use the switch because we are running on Windows Server 2008. – Sandra Apr 10 '14 at 10:29
  • and ?? this command works perfectly on windows 7 and 2008R2, i cant test on 2008 but i'm almost sure that it works too – Loïc MICHEL Apr 10 '14 at 10:32
  • two more suggestions : can you try without the -argumentlist and what if you start dmt from cmd ? see my last edit. – Loïc MICHEL Apr 10 '14 at 10:51
  • do you mean running command `powershell.exe -version 2`? if after that I check the PS version it returns 3, is that normal? – Sandra Apr 10 '14 at 10:52
  • That depends upon how you're checking the PS version. Are you using `$PSVersiontable`? – alroc Apr 10 '14 at 11:25
  • i'm pretty sure the `-argumentlist` is destinated to stat-process, not to dmt. Could you try : `$Param = @("-user=`"$User`"";"-pass=`"$Psw`"";"-server=$SERVER";"-port=$PORT";"-import=`"$Import`"";"-source=`"$file`"";"-add=true";"-update=false";"-noui=true"); Start-Process -nonewwindow $DMTPATH $Param -Wait` – Loïc MICHEL Apr 10 '14 at 11:43
  • I would try without using `start-process` as it seems to be complicating things. Invoke external commands with `&` eg. `& c:\windows\app.exe param1 param2 param3`. Good reference for external commands here:http://edgylogic.com/blog/powershell-and-external-commands-done-right/ – andyb Apr 10 '14 at 23:08
0

I run into the same problem. I noticed if the -noui=true is removed, it seems to work.

NKCool
  • 1