How to RUN a PowerShell script

Hallo,

Maybe it’s simple but… how can I run a powershell script from Clarion?

RUN(‘test.ps1’) - doesn’t work
RUN(‘test.ps1’,0,0) - doesn’t work
RUN(LONGPATH()&’\test.ps1’) - doesn’t work
RUN(‘powershell.exe ‘&LONGPATH()&’\test.ps1’) - doesn’t work

Thank you for any help.
Robert

Have you tried
Run(‘PowerShell -noexit test1.ps1’)

1 Like

A Batch file can call Powershell so could run a PS script. From Clarion RUN your BAT file.

I use the below to Zip up a folder with PowerShell Compress:

ROBOcopy %SrcFld% %BakFld% ^
 *.clw *.inc  *.app *.dct  *.cwproj *.sln *.manifest *.red *.lib ^
 *.cur *.ico *.png *.gif *.bat *.ini *.msbuild *.txt *.h  ^
  /MT /R:2 /W:5  /PURGE /TEE /LOG+:%BakFld%\_RoboCopy.LOG

    echo Zip up folder %BakFld%
    echo --------------------------------
    powershell Compress-Archive -Path %BakFld%\* -DestinationPath %BakZip%
    IF ERRORLEVEL == 1 PAUSE
3 Likes

For WMI I suggest to use an ActiveScripting classes instead (I’m an author of both products):

2 Likes

I do like Mike’s ActiveScripting stuff very much, but you might also try Capesoft Oddjob (if you have it) to run your script if you really just want to run a .ps1 and capture output, etc.

Why to update the site?

3 Likes

I have OddJob but for this what I need it’s not good… it’s the same like NT ping class. From docs (Note this is a blocking, syncronous call.) so it will block the entire app until you got the response and I don’t think anyone wants that to happen.
The only workaround is with external tools like Powershell.

Thank you, now it’s working fine.
I had to Set-ExecutionPolicy to Unrestricted :man_facepalming:t2: (it’s a new pc in a very restrictive network)

Greetings,
Slightly off the topic but Carl inspired me to finish a very important task-Easily Backup to the Cloud.

Thank you Carl.

Batch File Attached.
Just place it in your APP folder and rename the extension to BAT.
Edit where needed.
_ZipMe.TXT (1.7 KB)

1 Like