Skip to content
PHP Logo

How can a PHP script on PC A execute a PowerShell script on PC B through a web interface?

To execute a PowerShell script on PC B from a PHP script on PC A through a web interface, you can use the `exec()` function in PHP to run a PowerShell command remotely. You will need to have proper permissions set up on PC B to allow remote execution of PowerShell scripts. Additionally, you may need to use a tool like PsExec to execute commands on a remote machine.

php
<?php
$command = 'powershell.exe -ExecutionPolicy Bypass -File \\PCB\path\to\script.ps1';
$output = shell_exec($command);
echo $output;
?>