How to RUN a PowerShell script

Tags: #<Tag:0x00007fc0db36e630> #<Tag:0x00007fc0db36e360>

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

1 Like

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

2 Likes

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
2 Likes

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

3 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.

1 Like

Why to update the site?

4 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)