khess
-
Posts
4 -
Joined
-
Last visited
Posts posted by khess
-
-
Perfect!!! the three \'s made it work! Thank you very much.
Finally got it working from cmd.exe.
powershell -command get-wmiobject win32_service -computername SERVER1 -filter \"startmode='auto'\"
So then you have to escape the backslashes and the quotes if you do it from PHP.
"powershell -command get-wmiobject win32_service -computername SERVER1 -filter \\\"startmode='auto'\\\""
-
Yes, this is PowerShell 3.0. The PowerShell command works, as does yours at the PS command line but yours doesn't work in my php script.
Is there a way that I can get the command to print out to screen to see how it's being parsed?
This hasn't worked:
$query = system (" command stuff");
echo $query;
And you've verified that the command itself works?
You're using "s around the entire command which means you [a] don't use them inside the string, if you even need them in the first place, or escape them.
system("powershell -command get-wmiobject win32_service -computername SERVER1 -filter startmode=auto");
[edit] Tried it, your command doesn't work. I can't figure out how to get it to accept quotes in the SQL it generates.
This does work:
Get-WmiObject win32_service -ComputerName SERVER1 | Where { $_.StartMode -eq "Auto" }
-
I am trying to solve the following problem in a php script.
This works:
system("powershell -command get-wmiobject win32_service -computername SERVER1");
It returns the expected results.
However, this returns nothing:
system("powershell -command get-wmiobject win32_service -computername SERVER1 -filter "startmode='auto'"");
I've tried escaping the single and double quotes in almost every possible combination. For example:
...SERVER1 -filter \"startmode=\'auto\'\"
and
...SERVER1 -filter \"startmode='auto'\"
And nothing seems to work past the SERVER1.
Anyone have any ideas?
Another PHP with PowerShell problem: Piping
in PHP Coding Help
Posted
Here's another interesting problem with running a powershell command inside system():
This command works at the PS command line:
PS> Get-wmiobject win32_service | Where-object { $_.StartMode -eq "Auto" }
But this command in a php script doesn't work:
system("powershell -command Get-wmiobject win32_service | Where-object { $_.StartMode -eq "Auto" }");
Even this doesn't work:
system("powershell -command Get-wmiobject win32_service | Where-object { $_.StartMode -eq \\\"Auto\\\" }");
I think it has to do with piping a command into another command. But it could be something else.
I still can't get the command that PHP sees to print out to screen so that I can see what's being parsed.
I think if I could see that, then I might not have to ask.