Information Technology Reference
In-Depth Information
}
Return $report
# End Function
}
To accomplish this, we had to identify the method used in the vSphere API. VMware pub-
lishes the vSphere API reference at www.vmware.com/support/pubs/sdk_pubs.html. In that
reference we were able to locate the CheckMigrate method. The documentation outlines the
required information to invoke the method. You should note in the provided script that we col-
lect those components, the VM, the destination host, and the resource pool as variables in the
script prior to calling the CheckMigrate method. The entirety of the script revolves around the
small amount of code listed here. Most of the script works on setting the required variables to
use the CheckMigrate method and then handling the output of that method:
# Set Variables needed for CheckMigrate Method
$pool = ($v.ResourcePool).ExtensionData.MoRef
$vmMoRef = $v.ExtensionData.MoRef
$hsMoRef = $DestHost.ExtensionData.MoRef
$si = Get-View ServiceInstance -Server $global:DefaultVIServer
$VmProvCheck = get-view $si.Content.VmProvisioningChecker
$result = $VmProvCheck.CheckMigrate($vmMoRef,$hsMoRef,$pool,$null,$null)
You should also note that this script is built as a PowerShell function. This means it is
designed to be loaded into a PowerShell console session and used like a cmdlet. For example,
once you have loaded the function, you can call this command:
Get-Cluster “ClusterName” | Test-vMotion
Loading PowerShell Functions
When you receive functions from trusted sources such as VMware or trusted community contribu-
tors, you'll need to make sure you load them into your PowerCLI/PowerShell session. h is is done
by “dot-sourcing” the function. You simply need to type a period followed by a space followed by
the complete path to the function. Unless you add the function to your PowerShell profi le, you will
need to reload it for each new session of PowerCLI, as in this example:
PowerCLI C:> . “C:\Test\Test-vMotion.ps1”
You should now have a solid understanding of the vast capabilities of PowerCLI and how to
get started. We've tried to provide you with the essential information that we have shared with
others to start their journey to automating their VMware environments. Remember to always
look to the community forums and bloggers for assistance as you navigate PowerCLI. We also
Search WWH ::




Custom Search