Skip to content

Instantly share code, notes, and snippets.

@jakerobinson
Created August 22, 2014 03:29
Show Gist options
  • Save jakerobinson/881ee72297c7bc974d1e to your computer and use it in GitHub Desktop.
Save jakerobinson/881ee72297c7bc974d1e to your computer and use it in GitHub Desktop.
function Export-VM
{
param
(
[parameter(Mandatory=$true,ValueFromPipeline=$true)] $vm,
[parameter(Mandatory=$true)][String] $destination
)
$ovftoolpaths = ("C:\Program Files (x86)\VMware\VMware OVF Tool\ovftool.exe","C:\Program Files\VMware\VMware OVF Tool\ovftool.exe")
$ovftool = ''
foreach ($ovftoolpath in $ovftoolpaths)
{
if(test-path $ovftoolpath)
{
$ovftool = $ovftoolpath
}
}
if (!$ovftool)
{
write-host -ForegroundColor red "ERROR: OVFtool not found in it's standard path."
write-host -ForegroundColor red "Edit the path variable or download ovftool here: http://www.vmware.com/support/developer/ovf/"
}
else
{
$moref = $vm.extensiondata.moref.value
$session = Get-View -Id SessionManager
$ticket = $session.AcquireCloneTicket()
& $ovftool "--I:sourceSessionTicket=$($ticket)" "vi://$($defaultviserver.name)?moref=vim.VirtualMachine:$($moref)" "$($destination)$($vm.name).ovf"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment