Pages

Wednesday, April 10, 2019

Deleting stuck VMware Horizon View VMs with viewdbchk.cmd

Problem

You have a pool of desktops that are currently in a status / state where you are unable to use the VMware Horizon 7 administrator console to remove:

Deleting (missing)

Maintenance mode (missing)

Solution

Older version of View required the administrator to manually remove references of the VMs from the ADAM database hosted on the View Connection Servers, the entries in the composer SQL database, virtual machine on vCenter (if it exists), as well as the Active Director computer object but newer version such as 7 now provide a tool named viewdbchk.cmd that automates this process.

This command can be found at the following directory:

C:\Program Files\VMware\VMware View\Server\tools\bin

Simply executing this command will provide you with the switches available:

C:\Program Files\VMware\VMware View\Server\tools\bin>viewdbchk.cmd

No command specified

ViewDbChk --findDesktop --desktopName <desktop name> [--verbose]

Find a desktop pool by name.

ViewDbChk --enableDesktop --desktopName <desktop name> [--verbose]

Enable a desktop pool.

ViewDbChk --disableDesktop --desktopName <desktop name> [--verbose]

Disable a desktop pool.

ViewDbChk --findMachine --desktopName <desktop name> --machineName <machine name

> [--verbose]

Find a machine by name.

ViewDbChk --removeMachine --machineName <machine name> [--desktopName <desktop n

ame>] [--force] [--noErrorCheck] [--verbose]

Remove a machine from a desktop pool.

ViewDbChk --scanMachines [--desktopName <desktop name>] [--limit <maximum delete

s>] [--force] [--verbose]

Scan all machines for problems. The scan can optionally be limited to a speci

fic desktop pool.

ViewDbChk --help [--commandName] [--verbose]

Display help for all commands, or a specific command.

C:\Program Files\VMware\VMware View\Server\tools\bin>

Using automated scan option to detect problematic virtual machines

The recommended first step to take is to use the scanMachines switch to allow the tool to automatically detect any problematic machines in the pools. Note that the tool needs the pool to be disabled in order for it to scan it and it is best to disable provisioning as well to prevent new machines from being provisioned when one is deleted.

Here is a sample of the process with a limit of 200 machines specified:

viewdbchk.cmd --scanMachines --limit 200

C:\Program Files\VMware\VMware View\Server\tools\bin>viewdbchk.cmd --scanMachine

s --limit 200

Checking for machines with errors...

Connecting to vCenter "https://contukvc01.contoso.com:443/sdk". This m

ay take some time...

Connecting to vCenter "https://contdrvc01.contoso.com:443/sdk". This m

ay take some time...

Found 35 machine(s) with errors in 4 desktop pool(s)

Processing desktop pool "cont_disaster_recovery"

Desktop Pool Name: cont_Disaster_Recovery

Desktop Pool Type: STICKY_TYPE

VM Folder: /UK DR/vm/VM View/cont_Disaster_Recovery/

Desktop Pool Disabled: true

Desktop Pool Provisioning Enabled: false

Checking connectivity...

Machine "contDR-008" has errors

VM Name: contDR-008

Creation Date: 9/24/18 9:21:43 PM BST

MOID: vm-10521

VM Folder: /UK DR/vm/VM View/cont_Disaster_Recovery/contDR-008

VM State: MAINTENANCE

VM Missing In vCenter: true

Do you want to remove the desktop machine "contDR-008"? (yes/no):

As shown above, the tool will prompt you with the suspected problematic virtual desktop name and ask if you would like to remove it. It is important that you verify the virtual machine identified is indeed a machine you would like to delete as you cannot reverse the process.

Selecting yes to the machine will output the following:

Do you want to remove the desktop machine "contDR-008"? (yes/no):yes

Shutting down VM "/UK DR/vm/VM View/cont_Disaster_Recovery/contDR-008"...

** ERROR: EXCEPTION: VM not found: vm-10521 **

Removing VM "/UK DR/vm/VM View/cont_Disaster_Recovery/contDR-008" from inventory..

.

** ERROR: EXCEPTION: VM not found: vm-10521 **

Removing ThinApp entitlements for machine "/UK DR/vm/VM View/cont_Disaster_Recove

ry/contDR-008"...

Removing machine "/UK DR/vm/VM View/cont_Disaster_Recovery/contDR-008" from LDAP..

.

Running delete VM scripts for machine "/UK DR/vm/VM View/cont_Disaster_Recovery/T

MRDR-008"...

Machine "contDR-004" has errors

VM Name: contDR-004

Creation Date: 9/24/18 9:21:43 PM BST

MOID: vm-10520

VM Folder: /UK DR/vm/VM View/cont_Disaster_Recovery/contDR-004

VM State: MAINTENANCE

VM Missing In vCenter: true

Do you want to remove the desktop machine "contDR-004"? (yes/no):

The tool will proceed with scanning other machines once the earlier problematic machine has been deleted. Once all of the identified VMs are deleted, the tool will ask if you would like to re-enable provisioning if it is currently disabled:

With the pass of the first pool completed, it will move onto the next pool but if the pool is not disabled then it will ask if I can be disabled. This is obviously potentially service impacting so if the pool is in production and being used, select no.

Checking connectivity...

The desktop pool "Standard_Desktop" must be disabled before proceeding. Do

you want to disable the desktop pool? (yes/no):

Manually identifying problematic virtual machines and removing them

There will be times when the scanMachines switch would not be able to identify problematic machines. An example of this would be pools that are stuck in the Deleting state:

You can find these machines in the Machine view but unable to click into the pool itself:

The method to remove these machines would be to manually specify the machine name and the pool using the removeMachine switch. The following is an example of the cmdlet:

viewdbchk.cmd --removeMachine --machineName UKVD-050 --desktopName Building__VMs

The following is an example of the output:

C:\Program Files\VMware\VMware View\Server\tools\bin>viewdbchk.cmd --removeMachi

ne --machineName contUKVD-050 --desktopName Building__VMs

Looking for desktop pool "Building__VMs" in LDAP...

Desktop Pool Name: Building__VMs

Desktop Pool Type: STICKY_TYPE

VM Folder: /Hemel Hempstead/vm/contE UK Windows 10 VDI/London/Gold 2vCPU - 8GB

RAM/Building__VMs/

Desktop Pool Disabled: true

Desktop Pool Provisioning Enabled: false

Desktop Pool Provisioning Error: The task was canceled by a user.

Looking for machine "/Hemel Hempstead/vm/contE UK Windows 10 VDI/London/Gold 2vCP

U - 8GB RAM/Building__VMs/contUKVD-050" in vCenter...

Connecting to vCenter "https://contukvc01.contoso.com:443/sdk". This m

ay take some time...

** ERROR: NOT FOUND **

Checking connectivity...

Found machine "contUKVD-050"

VM Name: contUKVD-050

Creation Date: 3/6/19 6:48:14 AM GMT

MOID:

VM Folder: /Hemel Hempstead/vm/contE UK Windows 10 VDI/London/Gold 2vCPU - 8GB

RAM/Building__VMs/contUKVD-050

VM State: DELETING

VM Missing In vCenter: true

Do you want to remove the desktop machine "contUKVD-050"? (yes/no):Yes

LDAP record for machine "contUKVD-050" is incomplete.

Trying to remove machine by name...

Looking for machine "/Hemel Hempstead/vm/contE UK Windows 10 VDI/London/Gold 2vCP

U - 8GB RAM/Building__VMs/contUKVD-050" in vCenter...

** ERROR: NOT FOUND **

Removing ThinApp entitlements for machine "/Hemel Hempstead/vm/contE UK Windows 1

0 VDI/London/Gold 2vCPU - 8GB RAM/Building__VMs/contUKVD-050"...

Removing machine "/Hemel Hempstead/vm/contE UK Windows 10 VDI/London/Gold 2vCPU -

8GB RAM/Building__VMs/contUKVD-050" from LDAP...

Running delete VM scripts for machine "/Hemel Hempstead/vm/contE UK Windows 10 VD

I/London/Gold 2vCPU - 8GB RAM/Building__VMs/contUKVD-050"...

Provisioning has been disabled for the desktop pool "Building__VMs". Do you want

to enable it? (yes/no):

Repeat the same for all the other VMs and the pool will be successfully removed.

1 comment:

Paul Murphy said...

Very helpful! Thank you for posting this.