Hi All,
Not sure if this is the right place to flag this question. but just wanted to check. I am trying to connect to my vsphere server and collect info about VMs though my php code:
My PHP Code is below:
==================
<?php
$vm = $_POST['search'];
$getvm ="Get-VM $vm | Format-List *";
$stats ="Connect-VIServer x.xxx.xxx.xxx -User xxx -Password xxxx"| out-null; write 'VM Info'; $getvm";
$statscli = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy Bypass -psc \"C:\\Program Files (x86)\\VMware\\Infrastructure\\vSphere PowerCLI\\vim.psc1\" -Command \"{$stats}\"";
$query = shell_Exec($statscli);
echo ('<pre>');
echo $query;
echo ('<pre>');
?>
And the Error Message I get:
=====================
x86 : The term 'x86' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:24
+ -psc C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1
-Com ...
+ ~~~
+ CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFound
Exception
+ FullyQualifiedErrorId : CommandNotFoundException
VM Info
Get-VM : The term 'Get-VM' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:190
+ ... ite 'VM Info'; Get-VM aaa | Format-List *
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-VM:String) [], CommandNotFo
undException
+ FullyQualifiedErrorId : CommandNotFoundException
I am new to PowerCLI and PHP and got stuck on a critical project. My question is how can we pass C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1 from PHP point of view if any PHP Experts around in the forum who works with PowerCLI help me..
Thanks
The PSConsoleFile argument (-psc) is not interpreted correctly.
Try placing single quotes around the filename, something like this
$statscli = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy Bypass -psc \'C:\\Program Files (x86)\\VMware\\Infrastructure\\vSphere PowerCLI\\vim.psc1\' -Command \"{$stats}\""
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Thanks for your reply!!
I used the single quote and now its giving me the below error:
-psc : The term '-psc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + -psc \'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1\'
Thanks
I don't know the rules in PHP, but perhaps you should escape the minus sign as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
