Running a PowerShell script from ShellExecute

I am trying to launch a simple PowerShell script from AFL. I normally use a shortcut in the OS that works fine, but I'd rather launch this from a button in Ami.

If I use the following, it successfully launches PowerShell but immediately closes without executing the script. The script works fine if I launch it manually.

ShellExecute ("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "C:\\Users\\steve\\Desktop\\TransferLogsToDEV.ps1", "");

Any ideas as to what I am doing wrong or what I can try?

The PS script is simple it just copies files from my trading computer to my dev computer.

[string]$sourceDirectory  = "\\TRADINGCOMPUTER\AmiBroker\Formulas\Logs\*"
[string]$destinationDirectory = "C:\Program Files\AmiBroker\Formulas\Logs\"
Copy-item -Force -Recurse -Verbose $sourceDirectory -Destination $destinationDirectory

Hello vmonkey,

please call Powershell and Script via .cmd ( batch ) ...

_SECTION_BEGIN( "Sample: Execute Powershell script" );

fPSTrigger = ParamTrigger( "Trigger Powershell Script", "Execute" );

if( fPStrigger )
    ShellExecute( "C:\\Temp\\Hello-World.cmd", "", "", 1 );


Sample: Hello-World.cmd

Powershell.exe -executionpolicy remotesigned -File C:\Temp\Hello-World.ps1

Sample: Hello-World.ps1

Write-Host "Hello, World!"

Best regards,


Really appreciate the help @Pietro!

Thank you.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.