Created
August 22, 2014 03:29
-
-
Save jakerobinson/881ee72297c7bc974d1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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