cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Automate POImports with Adapter on Premises

I have been able to create a scheduled task to run the import but what can I do to have it run only if there is a file to run. There may not be files to run everyday. I don't know how to write powershell.

(7) Replies

Attached is a PowerShell script to run a command if a file exists.  Simply place your file name at the end of the Test-Path statement at the top of the file.  As an example, this script will call ipconfig.exe if the specified file exists.

--Mark

checking the file works but when I do a start-process MGSBI.exe /Import=POImport /ConfigFile=create_purchase.xml it keeps saying it [A positional parameter cannot be found that accepts argument '/ConfigFile=Create_Purchase.xml'] I tried it with quotes and without quotes the file is in the same location as the MGSBI.EXE because when I listed it with the path and file it didn't work. 

I tried my Powershell file with a call to MGSBI and it did run.  I've substituted your parameters in it; you simply need to enter the file path to the file you're checking for and that of your business adapter's XML.  The file I provided does not use start-process; it calls MGSBI natively as part of the Powershell file.

If you want to use the start-process cmdlet, then @ppyrzynski 's suggestion should work, or you could call it like this:

Start-Process -Filepath "C:\path\to\mgsbi\MGSBI.exe" -ArgumentList "/Import=POImport /ConfigFile=c:\path\to\your\xml\create_purchase.xml"

--Mark

Not sue if your start-process code will work like this, have you tired it @mfeinman ? I believe arguments in ArgumentList have to be separated with a comma. Also, if a path contains blank spaces it should be enclosed with single or double quotes, shouldn't it? I'm not a PS expert so if I'm wrong, just let me know. 

Paweł

Parameters can be passed as either a single string separated by spaces or as individual strings separated by commas.  Take a look at example 7 here.  If there are spaces in the string that don't represent parameters, then yes, they need to be surrounded by double quotes.  Bottrm's example didn't have any.

-ArgumentList

Specifies parameters or parameter values to use when this cmdlet starts the process. Arguments can be accepted as a single string with the arguments separated by spaces, or as an array of strings separated by commas. The cmdlet joins the array into a single string with each element of the array separated by a single space.

The outer quotes of the PowerShell strings aren't included when the ArgumentList values are passed to the new process. If parameters or parameter values contain a space or quotes, they need to be surrounded with escaped double quotes. 

For the best results, use a single ArgumentList value containing all the arguments and any needed quote characters.

--Mark

Thanks Mark, 

You are, of course, right. Tested and worked. 

Hey. Try this:

$argList=("/Import=POImport", "/ConfigFile=`"<PATH TO YOUR XML FILE>\Create_Purchase.xml`"")
Start-Process "C:\Program Files (x86)\Flexera Software\FNMP Business Adapter Studio\MGSBI.exe" -ArgumentList $argList