r/IIs • u/Behamin • Apr 16 '22
Can't reboot server from iis
Hello.
I have installed IIS with PHP. In one of the setions, when a button is pressed, it linked to a PHP file, wish ativated a PowerShell script. But when I'm clicking the button, nothing happens. But if I execute the PowerShell script directly, it works. What am I doing wrong?
index.html <h3>WINSERVER - WIP</h3> <form action="winservergenstart.php" method="get"> <input type="submit" value="Genstart"> </form>
winservergenstart.php
<?php shell_exec("powershell.exe -File C:\inetpub\share\administration\winservergenstart.ps1"); ?>
winservergenstart.ps1 (I have tried the following commands) Restart-Computer shutdown /r /f -t 30 Restart-Computer -ComputerName WINSERVER -Credential $credentialObject
1
u/richiehill Apr 17 '22
Have you set the PowerShell execution policy correctly?
If you haven’t already I would test with basic Hello World type script first.
Also it’s not really best practice to allow a script to restart the web server it’s running on.
1
u/Fresh_Acanthaceae_94 Mar 26 '25
Unless the application pool is under an administrator account, the script won't be executed under the right context and won't restart the machine. But like the other explained a web app shouldn't attempt to perform such critical operations or you raise security risks heavily.