| | |

Nutanix AHV and Citrix MCS: Adding a persistent disk via Powershell

3 min read

PRISM UI

Yet another powershell blog, this one is about adding a persistent disk via powershell on an AHV hosted non-persistent VM created with Citrix MCS. The use case here would be persistent write cache for App-V cache, AV definitions, log files etc.

Here’s another blogpost about writing scripts, just to make sure; the last few scripts can be found here:

One of the comments I hear from time to time on using MCS vs PVS is the option to have a writeable volume added to the Target VM for things like AV definitions, logfiles and App-V or UEM caches. Albeit fully supported by Citrix there’s no UI workflow in Studio to add this persistent disk using Citrix MCS. This means you’ll have to assign that secondary disk using other means, in my world this typically means scripting.

Using Nutanix ACLI this should be pretty straightforward and my options are outlined by -tab-:

 vm.disk_create KBTestVM91 
bus=                    Device bus                                                                                                                                                          
cdrom=                  Indicates if the disk is a CDROM drive                                                                                                                              
clone_from_adsf_file=   Path to an ADSF file                                                                                                                                                
clone_from_image=       An image name/UUID                                                                                                                                                  
clone_from_vmdisk=      A vmdisk UUID                                                                                                                                                       
clone_min_size=         Minimum size of the resulting clone (only applies to cloned disks)                                                                                                  
container=              Container (only applies to newly-created disks)                                                                                                                     
create_size=            Size of new disk                                                                                                                                                    
device_uuid=            Device UUID                                                                                                                                                         
empty=                  Whether the disk is empty (only applies to CDROMs)                                                                                                                  
index=                  Device index on bus                                                                                                                                                 
scsi_passthru=          Passthrough disk?  

A simple onliner could be used to add a 10Gb disk to this VM:

vm.disk_create KBTestVM91 bus=scsi container=VDI create_size=10G

Although this is a good start it doesn’t allow us for bulk changing VMs and it doesn’t allow a wildcard for the VM name so back to posh to loop through the VMs and add a disk based on a wildcard:


# kees@nutanix.com
# @kbaggerman on Twitter
# https://blog.myvirtualvision.com
# Created on March 4, 2019


# Setting parameters for the connection
[CmdletBinding(SupportsShouldProcess = $False, ConfirmImpact = "None") ]
 
Param(
    # Nutanix cluster IP address
    [Parameter(Mandatory = $true)]
    [Alias('IP')] [string] $nxIP,   
    # Nutanix cluster username
    [Parameter(Mandatory = $true)]
    [Alias('User')] [string] $nxUser,
    # Nutanix cluster password
    [Parameter(Mandatory = $true)]
    [Alias('Password')] [System.Security.SecureString] $nxPassword
)
 


# Adding PS cmdlets
$loadedsnapins=(Get-PSSnapin -Registered | Select-Object name).name
if(!($loadedsnapins.Contains("NutanixCmdletsPSSnapin"))){
   Add-PSSnapin -Name NutanixCmdletsPSSnapin 
}

if ($null -eq (Get-PSSnapin -Name NutanixCmdletsPSSnapin -ErrorAction SilentlyContinue))
{
    write-log -message "Nutanix CMDlets are not loaded, aborting the script"
    break
}


Function write-log {
    <#
       .Synopsis
       Write logs for debugging purposes
       
       .Description
       This function writes logs based on the message including a time stamp for debugging purposes.
    #>
  param (
  $message,
  $sev = "INFO"
  )
  if ($sev -eq "INFO"){
    write-host "$(get-date -format "hh:mm:ss") | INFO | $message"
  } elseif ($sev -eq "WARN"){
    write-host "$(get-date -format "hh:mm:ss") | WARN | $message"
  } elseif ($sev -eq "ERROR"){
    write-host "$(get-date -format "hh:mm:ss") | ERROR | $message"
  } elseif ($sev -eq "CHAPTER"){
    write-host "`n`n### $message`n`n"
  }
} 
 
# Connecting to the Nutanix Cluster
$nxServerObj = Connect-NTNXCluster -Server $nxIP -UserName $nxUser -Password $nxPassword -AcceptInvalidSSLCerts

if ($null -eq (get-ntnxclusterinfo))
{
    write-log -message "Cluster connection isn't available, abborting the script"
    break
}

## VM Creation
# Setting Variables
$VMPrefix = Read-Host -Prompt 'Input your VM Prefix including the wildcard (*)'

# Searching for the VM defined
write-log -message "Searching for VMs with the prefix $VMPrefix"
$vminfo = Get-NTNXVM | Where-Object {$_.vmName -like $VMPrefix}

# Looping thru all VMs starting with the prefix and adding a disk
Foreach ($vm in $vminfo) {
        Try
        {
        $vmId = ($vm.vmid.split(":"))[2]
        write-log -message "VM found matching the naming: $($vm.vmName) and VM ID $($vmID)"
            ## Disk Creation
            Try
            {
            # Setting the SCSI disk of 50GB on Container ID (get-ntnxcontainer -> ContainerId)
            $diskCreateSpec = New-NTNXObject -Name VmDiskSpecCreateDTO
            $diskcreatespec.containerid = 1265
            $diskcreatespec.sizeMb = 12400

            # Creating the Disk
            $vmDisk =  New-NTNXObject –Name VMDiskDTO
            $vmDisk.vmDiskCreate = $diskCreateSpec

            # Adding the Disk to the VM
            Add-NTNXVMDisk -Vmid $vmId -Disks $vmDisk | out-null

            write-log -message "Adding a 2nd disk to $($vm.vmName)"
            }
            Catch
            {
            write-log -message "Failed to add a 2nd disk to $vm.vmName"
            }
        }
        Catch 
        {
        write-log -message "Could not find a VM with the name $($vm.vmName)"
        }

}

Disconnect-NTNXCluster *

write-log -message "Disconnecting from the cluster"

This resulted in the following output when running it against my AHV cluster:

Powershell output
Running the script

The following two tabs change content below.

Kees Baggerman

Kees Baggerman is Senior Technical Director — Performance & Solutions Engineering R&D at Nutanix, where he leads a global team responsible for defining how enterprise applications are delivered on the Nutanix platform. A former Citrix Technology Professional and NVIDIA Enterprise Platform Advisor, he has spent 15+ years driving EUC strategy and technical direction across architecture, product, and customer success. He has been writing here since 2011 — sharing what he learns at the intersection of platform engineering and enterprise IT.
Kees Baggerman

Kees Baggerman

Senior Technical Director at Nutanix - Former Citrix CTP - NVIDIA Enterprise Platform Advisor - 15+ years in EUC

Kees Baggerman is Senior Technical Director — Performance & Solutions Engineering R&D at Nutanix, where he leads a global team responsible for defining how enterprise applications are delivered on the Nutanix platform. A former Citrix Technology Professional and NVIDIA Enterprise Platform Advisor, he has spent 15+ years driving EUC strategy and technical direction across architecture, product, and customer success. He has been writing here since 2011 — sharing what he learns at the intersection of platform engineering and enterprise IT.

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.