PowerCLI

 View Only
  • 1.  upload vmdk as a boot drive to vsphere

    Posted Jan 13, 2023 02:20 PM

    Hello Community,

    I currently try to upload a vmdk (virtual disk file) to a vm on Vsphere
    The vmdk is from an ova file

    This is how I try to do it with powercli:
    // connect to server
    Connect-VIServer -Server domain.to.my.server.net
    // Create a new vm
    New-VM -Name "vm-name" -Datastore "global-sas-harddrives" -NumCpu 2 -MemoryGB 4 -NetworkName "networkName" -VMHost "domain.to.vmHost.net" -Location "foldername"
    // upload the local vmdk to a folder in a datastore
    $ds = Get-Datastore -Name "global-sas-harddrives"
    New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" > $null
    Copy-DatastoreItem -Item "C:/path/to/disk.vmdk" -Destination "ds:/datastore-folder-name/disk.vmdk"
    // copy the vmdk file to the folder of the newly created VM
    Copy-DatastoreItem -Item "ds:/datastore-folder-name/disk.vmdk" -Destination "ds:/vm-name/vm-name_bootdisk.vmdk"
    // everything upt to here seems to work fine but now i am struggling

    // I tried:
    New-HardDisk -VM "vm-name" -DiskPath "[global-sas-harddrives] vm-name/vm-name_bootdisk.vmdk"
    // but here I get: Incompatible device backing specified for device '0'.

    // I also tried the solution from a forum post from 2014 https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Adding-copied-harddisk-VMDK-to-a-VM/m-p/979840
    add-HD -VMname "vm-name" -Filename "[global-sas-harddrives] vm-name/vm-name_bootdisk.vmdk" -Controller "SCSI Controller 0"
    // here the task seems to go through without visible errors, but in the webgui it the drive has 0MB space
    // and the webgui says "Some of the disks of the virtual machine vm-name failed to load. The information present for them in the virtual machine configuration may be incomplete"

    Does anyone have an Idea what the problem is.
    And how I can further debug this Issue.

    Thanks a lot

     



  • 2.  RE: upload vmdk as a boot drive to vsphere
    Best Answer

    Posted Jan 13, 2023 02:44 PM

    You can't copy a VMDK like that.
    In the OVA file you most probably have a monolithic VMDK file, meaning the VMDK Descriptor is embedded into that single file.

    The easiest way to convert such a monolithic VMDK file to a VMDK header and VMDK data file would be to import the OVA into your vCenter, which results in a VM/appliance with the VMDK.

    Then copy the VMDK from that VM/appliance with the CopyVirtualDisk method.
    I have a sample script for using the CopyVirtualDisk method in HL Tools – Part 1 – Clone a VM without vCenter



  • 3.  RE: upload vmdk as a boot drive to vsphere

    Posted Jan 13, 2023 03:27 PM

    Hello LucD,
    Thanks a lot for the quick response.
    I will try the script and give feedback on if it worked or not.