Promotic

How to use PowerShell

Windows PowerShell is more advanced successor of the Command Line. It can be used for Windows system automation and configuration. It can also access the file system, registers, processes services, network components or selected applications.

Before the first usage it is recommended to verify whether the PowerShell is activated in the Windows OS. If not then follow the steps below:
Control panels>Programs and functions>Activate or deactivate Windows system functions => "Windows PowerShell 2.0".


If the PowerShell is to be used for executing commands that require higher permissions then you need to run 32- or 64-bit PowerShell "as administrator" (based on the 32- or 64-bit PROMOTIC runtime type used) and execute the following command:
Set-ExecutionPolicy Unrestricted
and confirm the option "A".
Example1:
Runs the ping command and then netstat
JavaScriptVBScriptSelect and copy to clipboard

var oShell = Pm.AxGetObject("new", "WScript.Shell");
var sInvoke = "";
sInvoke += "ping 127.0.0.1" + "\r\n";
sInvoke += "netstat";
oShell.Run("PowerShell " + sInvoke, 1, false);


Sending message from PowerShell into the PROMOTIC application:
This example allows using PowerShell and the Invoke-WebRequest command with the "POST" method to send a message into the PmaWebDir object. It can then be captured in the onPageAction event and with the help of the parameters pEvent.FilePath, pEvent.Method, pEvent.Params, pEvent.Data to process it further.
 
The Invoke-WebRequest method itself is preceded by authentication with the name and password that protects the Web server of the PROMOTIC application.
 
This script can be saved into the file with the ps1 extension and then run as a parameter of the PowerShell program.
$user = 'oper'
$pass = ''
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{Authorization = $basicAuthValue}
Invoke-WebRequest 'http://127.0.0.1/dir/test.htm?test=abc' -Headers $Headers -Body 'ahoj' -Method 'POST'


Sending a request for data from PowerShell into the PROMOTIC application:
This example allows using PowerShell and Invoke-WebRequest with the "GET" method to send a request for data to the PmaWebDir object.
 
The Invoke-WebRequest method itself is preceded by authentication with the name and password that protects Web server of the PROMOTIC application.
 
This script can be saved into the file with the ps1 extension and then run as a parameter of the PowerShell program.
$user = 'oper'
$pass = ''
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{Authorization = $basicAuthValue}
$res = Invoke-WebRequest 'http://127.0.0.1/dir/test.htm?test=abc' -Headers $Headers -Method 'GET'
$res.Content
# Script for processing received data


It can be captured in the onPageModify event and the parameters can be used to evaluate and return the requested data to the client. For example:
JavaScriptSelect and copy to clipboard

if (pEvent.FilePath == "test.htm")
{
pEvent.PageString = "Test OK";
}
PROMOTIC 9.0.23 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
Navigation:
 
 
- Running PowerShell commands from PROMOTIC application
 
 
- SVG
© MICROSYS, spol. s r. o.