What are the potential security risks and vulnerabilities associated with allowing PHP scripts to interact with Powershell commands on a web server?

Allowing PHP scripts to interact with Powershell commands on a web server can pose security risks such as command injection, unauthorized access to system resources, and potential exploitation of vulnerabilities in the Powershell environment. To mitigate these risks, it is important to sanitize user input, validate commands, and restrict access to only necessary Powershell functionalities.

<?php
// Sanitize user input
$user_input = $_POST['user_input'];
$clean_input = escapeshellarg($user_input);

// Validate and execute Powershell command
$command = "powershell.exe -command $clean_input";
$output = shell_exec($command);

echo $output;
?>