Send an EmailSupport 1-866-892-3154
 

Disable VMware View Pool using Powershell PowerCLI

Monday, January 23, 2012 - 6:23pm

Have you ever wanted to disable a VDI pool from the command line, but couldn’t find the right command for the job? As simple as it may seem to do, VMware has yet to equip the PowerCLI Snap-in with a “disable-pool” commandlet. Some may try to accommodate this by simply removing pool entitlements, but you can be faced with the following error:

Remove-PoolEntitlement : PowershellService::RemovePoolEntitlement FAILED, 
error=User with sid  has an active VDI Session on Pool . Entitlement cannot be 
removed until this session is terminated.

This error is the result of an active desktop session attached to the entitlement being removed, or worse, anywhere within the VDI system as this is a global property. What this means is that if a user has an entitlement to more than one pool, this command may fail every time. As a work-around, there is a value within the local ADAM database on the View broker server. It is a Boolean value with the name “pae-Disabled” and can be found in the vdi.vmware.int\Applications\ attribute of the local LDAP. Below is an example of how this value can be toggled from a script:

#Script takes parameters for pool name and action.
#Outcome is an enabled/disabled pool.
#Active sessions are disconnected before disabling.
#
#Dependencies: activedirectory module; vmware.view.broker
#
#Parameters (toggle-view_pool.ps1 -pool [poolname] –action [enable|disable])
#-pool: specifies the pool name
#-action: specifies the action imposed on the pool
param([string]$action = "", [string]$pool = "")
#Add Snapins/Modules
add-pssnapin vmware.view.broker
import-module activedirectory
#Connect to View ADAM database
$objPool = [ADSI]"LDAP://localhost/cn=$pool, ou=Applications, dc=vdi, dc=vmware, dc=int"
#Test if pool exists
if ($objPool)
{
      switch ($action)
      {
            #Enable pool instruction set
            "enable"
                  {
                        #Toggle pool on
                        $objPool.Put("pae-Disabled","0")
                   }
            #Disable pool instruction set
            "disable"
                  {
                        #Disconnect active sessions in specified pool
                        get-remotesession | where {$_.pool_id -eq $pool} | send-sessiondisconnect
                        #Disable pool
                        $objPool.Put("pae-Disabled","1")
                  }
                  #Default switch option
                  Default
                        {
                              write-host "***** Unknown value for action *****"
                              write-host ""
                        }
              }
      }
      else
      {
      Write-host "***** Please enter a valid Pool name *****"
      exit
}
#Clear object values
$objPool.Setinfo()
$objPool.close()

This script can be run from any scheduler by adding a PowerShell directive (powershell toggle-view_pool.ps1 -pool [poolname] –action [enable|disable]). As of this writing, toggling the “pae-Disabled” value is the only known method of successfully disabling pools from the command line. Let us know if you have tackled this using a different approach.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Twitter-style @usersnames are linked to their Twitter account pages.
  • Twitter-style #hashtags are linked to search.twitter.com.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

filter blog by author

filter blog by category

QUESTIONS?

You've got questions. And we've got answers. Give Clearpath a shout and we'll get to you with an answer...fast.

Give us a Call!

twitterfacebook

© 2011 Clearpath Solutions Group. All rights reserved.
Sales 1-800-961-2888       Support 1-866-892-3154