Automating Desktop in ‘Already Used’ State in VMware View

Getting a consistent view of the  VMware View virtual desktop environment is essential for proper management. However, sometimes non-persistent desktop pools become unusable over time. If a desktop that is set to refresh on log off is reset, the desktop goes into the Already Used state. This security feature prevents any previous session data from being available during the next log in.

Note: The View Desktop can also go into a Already Used state if a virtual machine is powered on in another ESX host in the cluster in response to a HA event or if it failed before a power on.

VMware KB1000590

An easy way to identify a desktop that is in Already Used state is to look at View Manager status under the inventory tab – Status. Unless you are or have a full time VMware View administrator you will not be checking for desktop Status every couple minutes. Would be nice to have that automated.



Some of the administrative tasks can be performed via PowerShell, however for this specific case VMware View does not implement an easy way to retrieve desktop status using PowerCLI.

VMware View controls desktop state in the ADAM database with the attribute pae-DirtyForNewSessions and pae-MachineState.


The virtual desktop state reported in the View Manager UI is in fact a mix of ADAM data and a volatile state based on the latest agent stats reported to the broker. Therefore, only looking into ADAM may not give you the exact state of the desktop.

At this time there’s no equivalent for looking at the state string in the View Manager UI in the supported PowerShell cmdlets. In this particular case you should be able to determine the state by checking both of the following are true:

(1) VM is in READY state, online and has zero sessions [use Get-DesktopVm cmdlet]
(2) Machine entry in ADAM has the pae-dirtyfornewsessions attribute set to 1 [Look up object in ADAM using the id in check 1].

Seems a little cumbersome to have to manually look into the ADAM database. However, it is possible to use vdmadmin.exe command to get a list of desktops in a Pool and the READY status. You can get the DN so that it’ll be easy for you to query ADAM.

#vdmadmin –M –d <Pool ID> -xml > desktops.xml


To make everyone life’s easier a have created a simple PowerShell script using the basis provided in my article VMware View Pool Membership Management using PowerCLI. The script collects virtual desktop pae-DirtyForNewSessions information via vdmadmin.exe, exporting the data to a XML file and importing importing into a hash table. The second function uses Get-DesktopVm to retrieve the machine state into a secondary hash table. Finally, both hash tables are combined to provide the results from both vdm-admin.exe and Get-DesktopVM.

Param ($username, $password, $connectionbroker, $pool_id)



Add-PSSnapin -Name "VMware.View.Broker"



# Retrieve desktop status using vdmamin.exe


[System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument


& 'C:\Program Files\VMware\VMware View\Server\tools\bin\vdmadmin.exe' -M -d $pool_id -xml > desktops.xml


$xmldt = $null


$xmldt = @{}


$xmldata = [xml] (Get-content -Path desktops.xml)




$xmldata.'machine-list'.'machine-entry' | %{







# Retrieve pae-DirtyForNewSessions from ADAM


$pae = $null


$pae = @{}


$paes = .\custom_vmware_view.ps1 -username $username -password $password -viewConnBroker $connectionbroker -action view-get-objects -ou servers | %{







$desktopvm = Get-DesktopVM -isInPool true



$output = $xmldt.keys | %{


    $machineName = $_


    $machineState = $xmldt.$_


    1 | select @{n=”name”;e={$machineName}},@{n=”machineState”;e={$machineState}},@{n=”dirtyForNewSessions”;e={$pae.$machineName}}





Write-Host $output



First, download the base script from Clint Kitson here and than my function here. Now, upload both scripts to any of the View Connection Brokers making sure they reside in the same folder. Now type: .\view.get-desktop.state.ps1 -username “administrator” -password “password” -connectionbroker “” -pool_id “pool_id

The resultant set is a lost of virtual desktops existing in the provided desktop pool (-pool_id) along with the Get-DesktopVM machineState and the vdmadmin pae-DiretyForNewSessions.




With control over the state of your desktops without having to look at the UI now it’s possible to create PowerShell functions to automate LinkeClone refresh, or execute operations with problematic desktops.

This article was first published by Andre Leibovici (@andreleibovici)



3 pings

    • Kevin H on 04/09/2012 at 9:41 am

    Here is another Great article and script to automate the refresh cycle on those in “Already Used” state.
    this saved me a lot of time every morning refreshing VMs. No more manually refreshing desktops for me.

  1. @Kevin H
    Thanks for pointing out yet another resource/solution.


  1. […] Andre Leibovici has a couple of great posts on VMware View. In this article, he discusses how CBRC metadata is handled when the RecomputeDigest_Task is invoked. The second article I saw discusses automating the “Already Used” state in VMware View. […]

  2. […] Manually checking based on data from ADAM is not supported by VMware as it’s considered internal and may change.I have previously discussed this same subject and proposed a similar solution. Automating Desktop in ‘Already Used’ State in VMware View. […]

  3. […] refer to “Automating Desktop in ‘Already Used’ State in VMware View” and “Automating Desktop in ‘Already Used’ State in VMware View –Part 2”.  Another […]

Leave a Reply