Powershell v2 create UEFI VM | Nutanix Community
Skip to main content

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?

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

 


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 $vmdisksi0]})
                }
                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? 


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

 


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  


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    :


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

 

Thanks again for all of the help.


No problem!

 

 


@slavjani yes there is been a change in the CMDlets commands .

first of all you need to connect to cluster:

Connect-NutanixCluster -server 172.16.3.10 -username admin -password $password  –AcceptInvalidSSLCerts

and if you cannot pass the password as a variable , just remove and it will ask you to type the password manually

once you are connected, you will be able to search each cmdlet for the new changes, 

for example:

New-NutanixObject BootConfig   is changed to New-NutanixObject -Name  BootConfig

 

 

Regards,


Hello comunity, i need info if these cmdlets are updated or there is new cmdlets for booting configuration?

i am preparing boot configuration for deploying VM with UEFI and SATA combination but those cmdlets are not working for me. I am using latest cmdlets downloaded directly from the Prism Element.

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

Those line are throwing errors…
Thanks and regards

 


Reply