To use this file, simply require the class in your project as follows:
require '/Path/To/PowerShell.php';
Create a new instance of the class as follows:
$powerShell = new \PowerShell();
var_dump($powerShell->__executePowerShellCommand());
Or
var_dump(\LibPowerShell\Controller::__executePowerShellCommand());
Then comment the last line of code:
var_dump(\LibPowerShell\Controller::__executePowerShellCommand());
Before doing all this, make values to the constants in the class as follows:
const SERVICENAME = NULL;
const COMPUTERNAME = NULL;
Change the null values as follows:
const SERVICENAME = "notepad";
const COMPUTERNAME = "PC1";
Or
Create 2 variables into your script as follows:
public static function __executePowerShellCommand($service_name, $computer_name) : boolean{
Then change the following 2 lines of code as follows:
From:
$SvcName = "' . \LibPowerShell\Controller::SERVICENAME . '"
$SvrName = "' . \LibPowerShell\Controller::COMPUTERNAME . '"
To:
$SvcName = "' . $service_name . '"
$SvrName = "' . $computer_name . '"
Then when you call the function, assign the variables values as follows:
var_dump($powerShell->__executePowerShellCommand("notepad", "PC1"));
Or
var_dump(\LibPowerShell\Controller::__executePowerShellCommand("notepad", "PC1"));
Please note that before applying to "PC1" for example, you must be enabling the power shell remoting on the remote PC using command called:
"Enable PSRemoting"
Then you must be under a DNS environment to make this script effective and running in a secured way.
If you have any other questions, I will be more than happy to oblige.
mostafa_a_hamid@hotmail.com
|