XenDesktop 7.0/7.1 with Esx 5.5: MCS attempts to delete vmdk’s that do not exist

Summary

An issue exists in XenDesktop 7.0/7.1 where MCS tries to delete orphaned snapshots every 6 to 8  hours with the error in vCenter

Delete virtual disk

File /vmfs/volumes/6528f12d-dbfe4312-f3ca-0017a4770da2/<vm name>-baseDisk/14 Jan 2016 00-11-42.9344Z.vmdk was not found

Issue:

When using XenDesktop 7.0/7.1 with VMWare Esx 5.5 cannot delete vmdk

Delete virtual disk

File /vmfs/volumes/6528f12d-dbfe4312-f3ca-0017a4770da2/<vm name>-baseDisk/14 Jan 2016 00-11-42.9344Z.vmdk was not found

The error occurs because XenDesktop MCS is trying to delete vm’s that no longer exist and keeps attempting to clean up redundant virtual machine files.

It is possible to view the redundant jobs using Citrix PowerShell plugins (installed by default on a Desktop Delivery Controller)

In order to view running jobs on XenDesktop type the following:

# Check Citrix Snappins have been loaded
IF ( (Get-PSSnapin -Name Citrix.MachineCreation.Admin.V2 -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Citrix.MachineCreation.Admin.V2
}

Get-ProvTask -maxrecordcount 999 -active $true | Where {$_.Type -eq “DisusedImageCleanup” -and $_.Status -ne "Finished" -and $_.Host -eq $env:computername} | measure

The above code will load Citrix PowerShell modules and return how many Provisioning Tasks are running that are a disk clean-up activity and is flagged as not being finished.

XenDesktopCannotDeleteVmdk_GetProvtask

In this case 144

Resolution:

In order to remove the job from the background tasks in MCS we will utilise the following cmdlets

To get the active jobs

Get-ProvTask

To stop the running jobs

Stop-ProvTask

To delete the stopped jobs

Remove-ProvTask

What we want to achieve is the following:

1) Check the script is running as an administrator

2) Check the correct Citrix module has been loaded

3) Find all the active disk clean-up jobs

4) End active disk clean-up activies

5) Delete the terminated jobs

6) Run a check to make sure there are no jobs left behind

The script can then be integrated into your image creation procedures to avoid the error appearing in the future.

 

Implementation:

The script will need to be run on each Desktop Delivery Controller to ensure all jobs have been cleared.

# Script to remove Redundant tasks from a DDC
# Script Name: MCSRedundantTasksDelete.ps1
#
# This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# ============================================================================
# Change History:
# 0.0.1 - 04/01/2016 - Adil Dean
#	- Script created
# 1.0 - 04/01/2016 - Adil Dean
#   - Added check for admin privaleges
# 1.1 - 08/01/2016
#   - Remove based on ddc powershell is running on
# 1.2 - 08/01/2016
#   - Run report after task completes
# 1.3 - 08/01/16
#   - Add specific Citrix module rather than Citrix*
# ============================================================================
# Known Bugs/Feature requests:
# - No validation of inputs
# ============================================================================
# Requirements:
# 
# Usage Instructions:
#
# - Run script from command line:
# .\MCSRedundantTasksDelete.ps1
# ============================================================================

#Initialise variables/Parameters


# Functions

Function IsAdmin  
{  
    If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")){
        Write-Output "This script required administrative privelages"
        Write-Output "Please re-run script in an elevated powershell session"
        Read-Host "Press any key to exit" | Out-Null
        Exit
    }
}

# Check if script has been run as admin
IsAdmin

# Check Citrix Snappins have been loaded
IF ( (Get-PSSnapin -Name Citrix.MachineCreation.Admin.V2 -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Citrix.MachineCreation.Admin.V2
}

Write-Output " **************************************************** "
Write-Output " **** PLEASE ENSURE ALL DISK CLEANUP TASKS HAVE  **** "
Write-Output " ****   COMPLETED BEFORE RUNNING THIS SCRIPT     **** "
Write-Output " ****    All pending tasks will be deleted       **** "
Write-Output " **************************************************** "
Read-Host " Press Enter to continue or Ctrl+C to exit " | Out-Null

# Stop running disk cleanup tasks
Get-ProvTask -maxrecordcount 999 -active $true | Where {$_.Type -eq “DisusedImageCleanup” -and $_.Status -ne "Finished" -and $_.Host -eq $env:computername} | Stop-ProvTask

# Delete stopped tasks
Get-ProvTask -maxrecordcount 999 | where {$_.Type -eq “DisusedImageCleanup” -and $_.WorkflowStatus -eq “Terminated”-and $_.Host -eq $env:computername} | Remove-ProvTask

# Report results
Write-Output "Active DisusedImageCleanup tasks:"
Get-ProvTask -maxrecordcount 999 -active $true | Where {$_.Type -eq “DisusedImageCleanup” -and $_.Status -ne "Finished" -and $_.Host -eq $env:computername} | measure
Write-Output "Finished DisusedImageCleanup tasks:"
Get-ProvTask -maxrecordcount 999 | where {$_.Type -eq “DisusedImageCleanup” -and $_.WorkflowStatus -eq “Terminated”-and $_.Host -eq $env:computername} | measure
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s