htakeuchi Posted March 29, 2013 Share Posted March 29, 2013 (edited) Hello: I have been developing a web tool to perform basic maintenance to 100's of MacOS units, which at this point it works fantastic. Now I am faced with the task of integrating 350 units in windows. The need is to send commands through powershell. I have tried to use system(), exec(), shell_exec() and have not been successful. The drop that spilled the cup this morning was... I sent a "reboot -r -t 01" command to a windows server hoping that it would perform a PSSession to a different non critical server, but to my surprise... You guessed it... I rebooted a production Server ... I am new to Powershell so I am not as fluent on it... But I am sure that it does not matter if you use a MacOS or a Windows or a Unix PHP server... the commands should be sent the same way and not platform dependent... Correct? Or is it that PHP needs a Powershell module installed such as ssh2?? As an example... How can I send a command to a Windows Unit from a php command? Let's say: shell_exec('powershell"Invoke-Command -ComputerName WindowsUnit1 -ScriptBlock { Get-Service dhcp } -Credential $Credentials"'); I have been getting the server to hang when trying to send this through a Windows based PHP server. I have added the "< NUL 2>&1" option at the end to get some feedback as well. On a MacOS based PHP server, the $credentials variable is unset, so.. in order for me to set the credentials, how can I do so? I hope someone here has faced this before and can shed some light my way. Thanks Hiroshi T Edited March 29, 2013 by htakeuchi Quote Link to comment https://forums.phpfreaks.com/topic/276291-how-can-i-send-powershell-commands-to-a-windows-server-from-a-php-server-on-macos/ Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 What was a "powershell"? Is it that perversion shell product which Microsoft was proud for many years Quote Link to comment https://forums.phpfreaks.com/topic/276291-how-can-i-send-powershell-commands-to-a-windows-server-from-a-php-server-on-macos/#findComment-1421802 Share on other sites More sharing options...
htakeuchi Posted March 29, 2013 Author Share Posted March 29, 2013 I wish I had a smarter comeback... but I think spending too much time to "Glorify" <-- Note sarcasm this hair pulling "PowerShell" thing... is no worth my last few strands of hair left over!!! Yet... I still need some light this way to try and understand why the hell am I not able to do this!!! Quote Link to comment https://forums.phpfreaks.com/topic/276291-how-can-i-send-powershell-commands-to-a-windows-server-from-a-php-server-on-macos/#findComment-1421803 Share on other sites More sharing options...
trq Posted March 30, 2013 Share Posted March 30, 2013 The reason this isn't working is because powershell doesn't exist in the mac. The commands you are trying to execute need to exist on the machine you are actually trying to execute them on. Quote Link to comment https://forums.phpfreaks.com/topic/276291-how-can-i-send-powershell-commands-to-a-windows-server-from-a-php-server-on-macos/#findComment-1421919 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.