0

I'm building a PowerShell script to run the following command on various servers:

arapx acc, Export ExportFile=\"C:\\Temp\\DEV_Refresh\\AccExport.txt\"

This code works:

Start-Process -FilePath '\\<fileserver>\Bin\arapx' -argumentList 'acc, Export ExportFile=\"C:\\Temp\\DEV_Refresh\\AccExport.txt\"'

Different servers have different paths for the output file so I tried to set a variable. But this fails:

$Dest_Folder="DEV_Refresh"
Start-Process -FilePath '\\<fileserver>\Bin\arapx' -argumentList 'acc, Export ExportFile=\"C:\\Temp\\${Dest_Folder}\\AccExport.txt\"'

This fails:

$Dest_Folder="DEV_Refresh"
Start-Process -FilePath '\\<fileserver>\Bin\arapx' -argumentList 'acc, Export ExportFile=\"C:\\Temp\\$(Dest_Folder)\\AccExport.txt\"'

And this fails:

$Dest_Folder="DEV_Refresh"
$argumentList = "'acc, Export ExportFile=\""C:\\Temp\\" + $Dest_Folder + "\\AccExport.txt\""'"
Start-Process -FilePath '\\<fileserver>\Bin\arapx' -argumentList $argumentList

Can anyone help me get the command to work with a varable?

Ken
  • 77
  • 9
  • Try `Start-Process -FilePath '\\\Bin\arapx' -argumentList ('acc, Export ExportFile=\"C:\\Temp\\' + $Dest_Folder + '\\AccExport.txt\"')` – zett42 Jun 06 '22 at 21:39
  • You almost never need to use start-process, unless you want to wait for the process. Either don't use quotes, or use the call "&" operator. – js2010 Jun 07 '22 at 18:11
  • In fact without -wait, start-process will run in the background. – js2010 Jun 07 '22 at 18:22

1 Answers1

1

The solution from zett42 works:

$Dest_Folder="DEV_Refresh"
Start-Process -FilePath '\\<fileserver>\Bin\arapx' -argumentList ('acc, Export ExportFile=\"C:\\Temp\\' + $Dest_Folder + '\\AccExport.txt\"')
Ken
  • 77
  • 9