2

Automating Desktop in 'Already Used' State in VMware View - myvirtualcloud.net

 2 years ago
source link: https://myvirtualcloud.net/automating-desktop-in-already-used-state-in-vmware-view/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Automating Desktop in ‘Already Used’ State in VMware View

  • 04/08/2012

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.SelectNodes("machine-list")
$xmldata.'machine-list'.'machine-entry' | %{
$xmldt.add($_.'machine-name',$_.state)
}
# 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 | %{
$pae.add($_.'pae-DisplayName',$_.'pae-DirtyForNewSessions')
}
$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 “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.

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK