Previous master basedisk is not getting deleted automatically when publishing new basedisk for dedicated MCS full clone catalog using powershell

Previous master basedisk is not getting deleted automatically when publishing new basedisk for dedicated MCS full clone catalog using powershell

book

Article ID: CTX272453

calendar_today

Updated On:

Description

When updating dedicated MCS catalog’s master image mapping via powershell as mentioned on CTX129205, previous master basedisk is not getting deleted.

  • Initially, MCS catalog wizard creates a folder as below on hypervisor (Sphere in this example)
    <catalog name>-baseDisk-datastore-31 and basedisk file inside this folder.
  • An update to this existing catalog via powershell (Publish-ProvMasterVmImage) creates new folder as  <catalog name>-baseDisk-datastore-31_1 and new basedisk inside this folder with same name as previous.
  • Expectation is, MCS should delete previous folder and its contents after creating new basedisk in new folder.
  • However, we do not see the delete activity, and Sphere (in this example) data store view shows two master base disks folders and base disks for single catalog as below:
           

 

Environment

The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.

Resolution

For New Machine Catalog

For a newly deployed catalog, refrain from using same name of snapshot if you are deleting existing snapshot during this process.
Example: ‘NewSnapshot4.snapshot’ was used to create the catalog. If you delete it and recreate with same name on vSphere, the issue might occur.


Instead, you can provide a different name (Example - NewSnapShot5) to avoid this problem.

For Already Affected Machine Catalog

Once a catalog is already in a situation as explained above, there is a chance that first basedisk folder will not be deleted by MCS automatically as it becomes unknown to Citrix and its DisusedImageCleanUp task.

Either you can delete all master base disk folders for the catalog, and start with a new snapshot name again. This will create master basedisk and you can run publish it to the same provisional scheme.

If you don’t wish to delete them all as you still want to keep the correct basedisk folder active, follow below steps to identify which is the currently mapped master basedisk to your provisional scheme, and then delete the other one(s).

Step 1
On DDC powershell run following, and make a note of ProvisioningSchemeUid for your affected catalog.

Get-ProvScheme | select ProvisioningSchemeName, ProvisioningSchemeUid


Step 2
On DDC powershell run the following to create a .csv output file containing a list of the current VM Image for each provisioning scheme. This basedisk and its folder can be kept active, and you can delete the other master basedisk folders as they are not referenced by Citrix.   
get-provschememastervmimagehistory -ShowAll -MaxRecordCount 3000 | ? {$_.ImageStatus -eq “Current”} | export-csv C:\temp\CurrentImage.csv
image.png
If the provisioning scheme in question does not appear on the report, increase the MaxRecordCount value and run the command again. 

Important Note
The basedisks referred in this article are not the disks directly used by MCS VDA VMs in dedicated full clone catalogs. This article is talking only about the master basedisk mapped to the provisional scheme, which will be used to provision new machines. The existing VMs do not have any connection to the master basedisk in full cloned dedicated catalog. As there is no dependency, even if you delete them completely, you can still create a new snapshot from master image and publish that snapshot to provisional scheme using the Posh Cmdlet Publish-ProvMasterVmImage. This will create a new basedisk, and can be used to provision new VMs.

------------
Equivalent SQL Query for Step 2: 
Run following query against site database and check the output. Output shows, the basedisk which is currently mapped to provisional scheme. This basedisk and its folder can be kept active, and you can delete the other master basedisk folders as they are not referenced by Citrix. 
Replace <CitrixSiteDbName> with your actual site database name

Replace <ProvisioningScehemUid> with the ProvisioningSchemeUid  copied from powershell output.

Select DiskId FROM [<CitrixSiteDbName>].[DesktopUpdateManagerSchema].[ProvisioningSchemeVMImageLocation]
Where MasterImageHistoryUid = (Select ProvisioningSchemeVMImageHistoryUid FROM [<CitrixSiteDbName>].[DesktopUpdateManagerSchema].[ProvisioningSchemeVMImageHistory]
Where ImageStatus = 'Current' and ProvisioningSchemeUid = '<ProvisioningScehemUid>')


 

Problem Cause

This problem occurs when you delete existing snapshot and create a new snapshot with same name. This method sometimes reports the previous disk as 'in use' as Citrix database keeps a reference of snapshots used and maps them to corresponding basedisks created. ‘DisusedImageCleanUp’ doesn’t run in this scenario against the specific disk.
 

Additional Information

https://support.citrix.com/article/CTX129205