You can create a flat VDisk object and attach it to a virtual machine as a hard disk. After that, you can verify whether the operation was completed successfully.

Prerequisites

  • Verify that you are connected to a vCenter Server system.
  • Verify that you have access to at least one virtual machine host.
  • Verify that there is at least one datastore mounted on the virtual machine host.

Procedure

  1. Mount the datastore on the virtual machine host and store the datastore in the $ds variable.
    $vmHost = Get-VMHost 'Host-A'
    $ds = Get-Datastore -RelatedObject $vmHost
  2. Create a flat, thin-provisioned virtual disk with 2-GB capacity on the $ds datastore.
    $vDisk = New-VDisk -Name 'VirtualDisk' -DiskType Flat -StorageFormat Thin -CapacityGB 2 -Datastore $ds
  3. Create a virtual machine named VirtualMachine with one hard disk and store this virtual machine in the $vm variable.
    $vm = New-VM -Name 'VirtualMachine' -VMHost 'Host-A' -Datastore $ds -DiskMB 512
  4. Power on the $vm virtual machine.
    Start-VM -VM $vm
  5. Attach the VDisk object to the $vm virtual machine.
    New-HardDisk -VM $vm -VDisk $vDisk
  6. Verify that the VDisk object has been attached and the virtual machine now has two hard disks.
    Get-HardDisk -VM $vm