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.
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.
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 “127.0.0.1” -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.