Question

Powershell v2 create UEFI VM

  • 26 October 2021
  • 7 replies
  • 49 views

Badge +1

Hello, I am trying to create a vm that will use UEFI and Secure boot with the new powershell cmdlets. With the version 1 cmdlets this was not possible. Does anyone know if this is possible with V2 or are we still required to use the API along with the powershell cmdlets?


7 replies

Badge

Yes, you should be able to do that in the v2 cmdlets.  You will want to create a boot config first.

Here is a sample boot config:

$boot=New-NutanixObject BootConfig
$boot.uefi_boot=$true
$boot.secure_boot=$true
$boot.boot_device_type='DISK'
$boot.disk_address=$diskAddress

 

Then apply that boot config to the VM.  

New-VM -Name TestBoot -NumVcpus 2 -MemoryMb 8000 -ClusterUUID <UUID> -BootConfig $boot

 

Badge +1

Thanks. This is a great start.

I am trying to add a disk from an image I have. Depending on the purpose of the VM I might have multiple disks from images. What I did in the past was:

$base = 'Server_2019_UEFI'

 

switch ($vmtype)
        {
            'IIS' {$vmdisks = $base,'IISData','IISLogs'}
            'SQL' {$vmdisks =$base,'SQL-2017' }
            'VM'  {$vmdisks = $base}
        }

                $vmDisk = New-NTNXObject -Name VMDiskDTO
                $diskCloneSpec = New-NTNXObject -Name VMDiskSpecCloneDTO
                IF($VMDisks.count -gt '1') {
                    $diskImage = (Get-NTNXImage | Where-object {$_.name -eq $vmdisks[0]})
                }
                ELSE
                {
                    $diskImage = (Get-NTNXImage | Where-object {$_.name -eq $vmdisks})
                }
                $diskCloneSpec.vmDiskUuid = $diskImage.vmDiskId
                $vmDisk.vmDiskClone = $diskCloneSpec   
            
            IF($VMDisks.count -gt '1') {
                        
                          $vmDisk = @($vmDisk)
                 Foreach ($disk in $vmdisks){
                 IF($disk -ne $VMDisks[0]){
                    $AddvmDisk = New-NTNXObject -Name VMDiskDTO
                    $AdddiskCloneSpec = New-NTNXObject -Name VMDiskSpecCloneDTO
                    $AdddiskImage = (Get-NTNXImage | Where-object {$_.name -eq $disk})
                    $AdddiskCloneSpec.vmDiskUuid = $AdddiskImage.vmDiskId
                    $AddvmDisk.vmDiskClone = $AdddiskCloneSpec
                    $vmDisk += $AddvmDisk
                    }
                }
            }
                $vmISODisk = New-NTNXObject -Name VMDiskDTO
                $vmISODisk.isCdrom = $true
                $vmISODisk.isEmpty = $true

 

 

So now I am thinking I need to use the:

 

$vmDisk = New-NutanixObject -Name VMDisk

 

And then add the $vmdisk.vm_disk_clone property with the UUID from the image in the repository? 

Badge

Correct. To clone you need to get the VM disk UUID first.  You might already have that handy.  If you don’t, you can grab that by getting the UUID of the image first ‘Get-Image’. Once you have the image UUID get the VM disk UUID with ‘Get-Image -ImageID <image UUID> -IncludeVmDiskId. VM disk image will be listed at vm_disk_id. 

From there the cloning is strait forward. 

  1. Create VMDiskAddress 

            $cloneDiskAddress=New-NutanixObject VMDiskAddress

            $cloneDiskAffress.vmdisk_uuid=’<VM Disk UUID>

  1. Create VMDiskSpecClone

           $vmDiskClone=New-NutanixObject VMDIskSpecClone

           $vmDiskClone.disk_address=$cloneDiskAddress

  1. Create VMDisk Object

          $vmDisk=New-NutanixObject VMDisk

          $vmDisk.is_cdrom=$false

          $vmDisk.vm_disk_clone=$vmDiskClone

 

Just throwing this out there as well for instances where you don’t want to clone.  To create a net new disk, you will need the storage container UUID.  You can grab the UUID with ‘Get-StorageContainer | ConvertTo-Json -depth 6’.

  1.  Create the vmDiskCreate spec

          $vmDiskCreate=New-NutanixObject VMDIskSpecCreate

          $vmDiskCreate.storage_container_uuid=’<UUID>’

          $vmDiskCreate.size=’800000’

  1. Create the vmDisk

          $vmDisk=New-NutanixObject VMDisk

          $vmDisk.is_cdrom=$false

          $vmDisk.disk_address=$diskAddress

          $vmDisk.vm_disk_create=$vmDiskCreate

 

Badge +1

Thanks again for the help. Very much appreciated.

I noticed 2 things just in case someone comes behind me here. First there is a typo on 

 

$cloneDiskAffress.vmdisk_uuid=’<VM Disk UUID>

It should be

 

$cloneDiskAddress.vmdisk_uuid=’<VM Disk UUID>

 

No big deal.

 

Secondly there is not type VMDIskSpecClone with New-NutanixObject. According to the help there is only:

Available object names are VMDiskAddress, BootConfig, VMDiskSpecCreate, VMDisk, VMNicSpec.

 

When I try to use it I get an error saying it is not in the dictionary.

I am using version 2.01 of the module. Is there a new version?

 

Get-Module Nutanix.Prism.PS.Cmds


ModuleType Version    PreRelease Name                              
----------         -------       ---------- ----                               
Script              2.0.1        Nutanix.Prism.PS.Cmds  

Badge

Good catch on the typo!

 

The 2.0.1 Modules will work with New-NutanixObject VMDiskSpecClone

 

Installed Modules:

PS > Get-InstalledModule

Version              Name                                Repository           Description -------              ----                                ----------           -----------

2.0.1                Nutanix.Cli                         PSGallery            Nutanix Powershell Commands

2.0.1                Nutanix.Prism.Common                PSGallery            Nutanix Prism Common module

2.0.1                Nutanix.Prism.PS.Cmds               PSGallery            Nutanix Prism Powershell Commands Module

 

Sample of output:

PS> $vmDiskClone=New-NutanixObject VMDiskSpecClone

PS> $vmDiskClone :

disk_address  :    

:mage_path :       

ndfs_filepath :  

minimum_size : 

minimum_size_mb  :

snapshot_group_id. :

container_uuid    :

Badge +1

Yup. It is case sensitive. Didn’t realize. 

 

Thanks again for all of the help.

Badge

No problem!

 

 

Reply