Hi,
For two weeks I have been looking for a way to retrieve information from PowerCLI to a web.Nothing found and wanted to know if it's possible in an easy way. I want to get some information from VMWare View into website and then run PowerCLI cmdlets according to some actions that users make on the app. Another problem i have is that the web is in another Linux machine than my VMWare View server so i have to do it remotely.
So, the question is, is possible to do what i'm searching for??
Regards.
If you are looking to place data that you get from PowerCLI onto a web page there are a couple of ways you could consider doing it.
Full Help can also be found online....
http://technet.microsoft.com/en-us/library/dd347572.aspx
or from powershell
get-help convertto-html -online
Hi,
Thanks to all. I'm trying to do something different now, because the convertto-html doesnt works for me. I'm trying to use convertto-csv to create a csv file in the local machine(Windows Server 2008). So i'm trying to do the next:
In a web server in the local machine (is only an example):
<?php
shell_exec('powershell.exe -psc "console.psc1" -c Get-Pool ');
?>
So, this code should execute the command and return the pools in view server. If i launch this command from cmd(only 'powershell.exe -psc "console.psc1" -c Get-Pool'), it works fine, but if i try to do this trouhght php returns:
WARNING: The following errors occurred when loading console C:\scripts\miConsola.psc1: Cannot load Windows PowerShell snap-in VMware.View.Broker because of the following error: The Windows PowerShell snap-in 'VMware.View.Broker' is not installed on this machine.
Why is it happening???
Regards.
P.D: Console.psc1 is a console generated with Export-Console that opens a PowerCLI console instead of a PowerShell console.
Hi,
I'm still unable to execute my PowerCLI scripts from PHP. If i execute my scripts from local machine by double-clicking, or launching them from cmd or powershell it works, but if i try to launch them from PHP with shell_exec() or exec() it doesn't works. So, what i'm suspecting is that if i try to launch them from PHP, the script will be launched with apache user permissions(www-data) and thats why powershell cannot execute fine them. The error is that powershell can not load the VMWare.View.Broker snapin into powershell so i can't use PowerCLI cmdlet's. Someone has any idea how can i solve this problem??
Regards.
P.D: I put the Add-PSSnapin in my scripts to try load the snapin but, powershell returns that this snapin is not installed.
Did you install the VMware View part that installs the VMWare.View.Broker snapin on the webserver where you run this script?
The webserver from where i execute my PowerCLI scripts is the same as the View Server.
Regards.
P.D: If i try to launch Powershell scripts (cmdlets that are strictly for powershell) works fine, the problem is with PowerCLI.
Did you upgrade View from v4.5 to v4.6? Then you should check Running the Add-PSSnapin VMware.View.Broker PowerShell command fails after upgrading to View 4.6. You then need to load the View cmdlets by calling the add-snapin.ps1 script.
I didn't upgraded. I installed 4.6 directly. In spite of this, i'm putting the Add-PSSnapin VMWare.View.Broker in the first line of my scripts. In fact, is this line which causes the error.... Powershell can't load the Snapin if the script is launched from PHP with exec or shell_exec, but it works if i launch the script directly double-clicking....It's crazy.
Regards.
Can you try what happens if you change the Add-PSSnapin command into a call of the add-snapin.ps1 script as described in th KB article?
OK. This has been useful. Now i can load the snapin, but still can't execute PowerCLI cmdlets. What i have now is a php file with the next sentence:
echo shell_exec('powershell -c "C:\scripts\myScript.ps1"');
And the script contains this:
. /PathToPowerCLISnapin
Get-Pool | Out-File "C:\scripts\myFile.txt"
This should create a file called myFile.txt which should have the content returned by Get-Pool cmdlet, but it doesn't. This cmdlet is not executed... Why??
Regards.
What happens when you run the 'powershell -c "C:\scripts\myScript.ps1"' command from a command prompt on the webserver?
It works fine if i do it from command prompt, that what's strange...
Does the php page run under the context of a system account or does it impersonate?
Is ExecutionPolicy set to remotesigned or other less restrictive policy?
The executionPolicy is set to ByPass(I know that it is dangerous but it is for testing why the error is happening..). The php page is a simple page under the htdocs in apache local server only for testing if i can launch powershell scripts in php, so it doesn't run under a system account, but one of the things i doubt is that if i use the exec or shell_exec from php, it will launch the command with the apache user privileges (www-data normally), so i'm not really sure if this is causing the problem.
Regards.
I believe the execution policy is per user. So if it runs in context of the apache account, that account would have to set it's execution policy.
The other thing is whether or not it's running in context of on the server or your local system.
Hi,
Finally i could execute a the powerCLi script with PHP, but now i have another problem(sorry...). When it executes, doesn't finsh until i close the ssh session i have opened previously. The code is this:
Hi. I have resolved the problem. I have added after my command an echo statemnet with some string and capture the output and when i see this string i can stop reading.
Thanks to all.
