Skip to content

Instantly share code, notes, and snippets.

@HostileCoding
HostileCoding / Invoking Scripts in Guest-VM.ps1
Last active August 29, 2015 13:57
Automate Oracle DB install using Invoke-VMScript
#Variable declaration
$vCenterIPorFQDN="10.0.1.210"
$vCenterUsername="Administrator@vsphere.local"
$vCenterPassword="vmware"
$ESXiHost="10.0.1.62"
$NumberOfVmToDeploy=2 #How many VM deploy from template
$OracleTemplate="OraTemplate"
$DestinationDatastore="datastore1"
$ESXiHostUsername="root" #ESXi Host username
$ESXiHostPassword="mypassword" #ESXi Host password
#Variable declaration
$vCenterIPorFQDN="10.0.1.210"
$vCenterUsername="Administrator@vsphere.local"
$vCenterPassword="vmware"
$LocationName="Datacenter" #This could be: Datacenter Name, Cluster Name, Host Name
$ClusterName="TestCluster" #Name of the Cluster on which you need to run the report
$OutputPath="C:\" #Location where you want to place generated report
Write-Host "Connecting to vCenter" -foregroundcolor "magenta"
Connect-VIServer -Server $vCenterIPorFQDN -User $vCenterUsername -Password $vCenterPassword
##################BEGIN FUNCTIONS
function connectServer{
try {
$connect = Connect-VIServer -Server $serverTextBox.Text -User $usernameTextBox.Text -Password $passwordTextBox.Text
$buttonConnect.Enabled = $false #Disable controls once connected
#Variable declaration
$vCenterIPorFQDN="192.168.243.40"
$vCenterUsername="Administrator@vsphere.local"
$vCenterPassword="vmware"
$ESXiHost="192.168.243.62"
$outputFile="C:\Users\Paolo\Desktop\mycharts.html"
$stat = "mem.usage.average" #Stat to measure
#Available stats
#cpu.usage.average
#Variable declaration
$vCenterIPorFQDN="10.0.1.210"
$vCenterUsername="Administrator@vsphere.local"
$vCenterPassword="vmware"
$OutputFile="C:\Users\Paolo\Desktop\Report.html" #Where you want to place generated report
Write-Host "Connecting to vCenter" -foregroundcolor "magenta"
Connect-VIServer -Server $vCenterIPorFQDN -User $vCenterUsername -Password $vCenterPassword
#A JavaScript to add some style to our report
#Variable declaration
$vCenterIPorFQDN="10.0.1.210"
$vCenterUsername="Administrator@vsphere.local"
$vCenterPassword="vmware"
$ClusterName="My Cluster" #Name of the cluster from which you want to retrieve VM infos
#Location where you want to place generated JSON Files.
#Please be aware that you should place them in the "data" folder in order to make WebPowerCLI read data from them
$OutputPath="C:\Users\Paolo\Desktop\data"
Write-Host "Depending on how many VMs you have in your cluster this script could take a while...please be patient" -foregroundcolor "magenta"
#Variable declaration
$vCenterIPorFQDN="192.168.243.40"
$vCenterPort="443"
$vCenterUsername="Administrator@vsphere.local"
$vCenterPassword="vmware"
$DatacenterFolder="DCFolder"
$DatacenterName="Datacenter"
$MgmtClusterName="MgmtCluster"
$OpenStackClusterNames=@("OpenStackCluster") #Cluster(s) managed by OpenStack
$MgmtHosts= @("192.168.243.144") #IP or FQDN of hosts participating in Management Cluster
<?php
$variable1=$_POST["sendpowercli"];
//Post Data
if ($variable1 != null){
$command = $variable1;
$powercli = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -psc \"C:\\Program Files (x86)\\VMware\\Infrastructure\\vSphere PowerCLI\\vim.psc1\" -Command \"& {$command}\"";
$query = shell_exec("$powercli");
#Variable declaration
$vCenterIPorFQDN="192.168.243.172"
$vCenterUsername="Administrator@vsphere.local"
$vCenterPassword="vmware"
$pathToVcloudAgent="/opt/vmware/vcloud-director/agent" #Path of vCloud Agent in vCloud Director virtual machine
$FileVcloudAgent="vcloudagent-esx51-5.1.0-799577.zip" #vCloud Agent file that will be installed
$downloadDestination="C:\Users\Paolo\Desktop" #Where to download vCloud Agent on local machine
$vCdVmName="vCloud Director" #Name of vCloud Director virtual machine
$vCdVmUsername="root" #vCloud Director virtual machine username
$vCdVmPassword="vmware" #vCloud Director virtual machine password
#Variable declaration
$vCloudIPorFQDN="192.168.243.50"
$vCloudUsername="User1"
$vCloudPassword="mypassword"
$vCloudOrganization="HostileCoding"
$outputFile="C:\Users\Paolo\Desktop\mobilereport.html"
#Connecting to vCloud
Connect-CIServer -Server $vCloudIPorFQDN -User $vCloudUsername -Password $vCloudPassword -Org $vCloudOrganization