<!--?php
//run http://127.0.0.1/vmware_power.php?install=y to install and configure powercli to apache user
if(array_key_exists ( "install" ,$_GET ) && $_GET["install"]=="y")
{
$PowerCliCommand='export HOME=/tmp/ && pwsh -c "& {Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP \$false -Confirm:\$false; Import-Module \"VMware.VimAutomation.Core\"; Set-PowerCLIConfiguration -InvalidCertificateAction "Ignore" -Confirm:\$false; Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Confirm:\$false}"';
exec($PowerCliCommand, $Output, $ErrorReturned);
echo(implode ( '<br-->' , $Output ));
}
else
{
$vSphereIP = '192.168.1.200';
$user = "myuser";
$password = "mypassword";
//$powercli_query = 'Get-VM | Select @{N=\'Name\';E={\$_.Name}}, @{N=\'UUID\';E={\$_.Config.Uuid}} ';
$powercli_query = 'Get-vm "XPTO-VM-MYMV" | %{\$m=\$_; \$v=Get-View \$_; \$h=Get-HardDisk \$_; \$t=Get-TagAssignment \$_; [pscustomobject] @{name=\$m.name;HostName=\$v.Guest.HostName; Uuid=\$v.Config.Uuid; VMid=\$v.MoRef.Value;GuestId=\$v.Config.GuestId;CreateDate=\$v.Config.CreateDate;MemoryGB=\$h.Parent.MemoryGB;Numcpu=\$h.Parent.Numcpu;CapacityGB=\$h.CapacityGB;TagAssignment=(\$t | Select-object Tag -ExpandProperty Tag| select-object Category,Name,Id);Net=[pscustomobject] @{Network=\$v.Guest.Net.Network; MacAddress=\$v.Guest.Net.MacAddress; IpAddress=(\$v.Guest.Net.IpConfig.IpAddress | foreach-object {[pscustomobject] @{IpAddress=\$_.IpAddress;PrefixLength=\$_.PrefixLength }}); Connected=\$v.Guest.Net.Connected;}}}';
$PowerCliCommand='export HOME=/tmp/ && pwsh -c "& {Import-Module VMware.VimAutomation.Core; \$teste=Connect-VIServer -Server (\"$vSphereIP\", \"$vSphereIP\") -User '.$user.' -Password \"'.$password.'\"; '.$powercli_query.'| ConvertTo-Json -Depth 4} "';
exec($PowerCliCommand, $Output, $ErrorReturned);
header('Content-Type: application/json');
echo(implode ( ' ' , $Output ));
}
?> |
<!--?php
//run http://127.0.0.1/vmware_power.php?install=y to install and configure powercli to apache user
if(array_key_exists ( "install" ,$_GET ) && $_GET["install"]=="y")
{
$PowerCliCommand='export HOME=/tmp/ && pwsh -c "& {Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP \$false -Confirm:\$false; Import-Module \"VMware.VimAutomation.Core\"; Set-PowerCLIConfiguration -InvalidCertificateAction "Ignore" -Confirm:\$false; Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Confirm:\$false}"';
exec($PowerCliCommand, $Output, $ErrorReturned);
echo(implode ( '<br-->' , $Output ));
}
else
{
$vSphereIP = '192.168.1.200';
$user = "myuser";
$password = "mypassword";
//$powercli_query = 'Get-VM | Select @{N=\'Name\';E={\$_.Name}}, @{N=\'UUID\';E={\$_.Config.Uuid}} ';
$powercli_query = 'Get-vm "XPTO-VM-MYMV" | %{\$m=\$_; \$v=Get-View \$_; \$h=Get-HardDisk \$_; \$t=Get-TagAssignment \$_; [pscustomobject] @{name=\$m.name;HostName=\$v.Guest.HostName; Uuid=\$v.Config.Uuid; VMid=\$v.MoRef.Value;GuestId=\$v.Config.GuestId;CreateDate=\$v.Config.CreateDate;MemoryGB=\$h.Parent.MemoryGB;Numcpu=\$h.Parent.Numcpu;CapacityGB=\$h.CapacityGB;TagAssignment=(\$t | Select-object Tag -ExpandProperty Tag| select-object Category,Name,Id);Net=[pscustomobject] @{Network=\$v.Guest.Net.Network; MacAddress=\$v.Guest.Net.MacAddress; IpAddress=(\$v.Guest.Net.IpConfig.IpAddress | foreach-object {[pscustomobject] @{IpAddress=\$_.IpAddress;PrefixLength=\$_.PrefixLength }}); Connected=\$v.Guest.Net.Connected;}}}';
$PowerCliCommand='export HOME=/tmp/ && pwsh -c "& {Import-Module VMware.VimAutomation.Core; \$teste=Connect-VIServer -Server (\"$vSphereIP\", \"$vSphereIP\") -User '.$user.' -Password \"'.$password.'\"; '.$powercli_query.'| ConvertTo-Json -Depth 4} "';
exec($PowerCliCommand, $Output, $ErrorReturned);
header('Content-Type: application/json');
echo(implode ( ' ' , $Output ));
}
?>