Jump to content

How can I send powershell Commands to a Windows server from a PHP server on MacOS?


htakeuchi

Recommended Posts

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   :o...  

 

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

 

 

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!!!  :

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.