«

»

Dec 11 2012

VMware View PowerShell AD LDS Set-State Function

Advertisement

Automation is system administrator’s best friend. Automating repetitive tasks is a key enabler in most IT environments. Whilst many of the desktop pool changes in VMware View can be made via PowerShell, not all objects are exposed.

I created the PowerShell function below and it will change a desktop pool property state in Active Directory Lightweight Directory Services database key. The function uses the PoolID property to receive an object representation and set the new state in the AD LDS database.

IMPORTANT: Interacting with AD LDS database is not supported by VMware. You may use the information and scripts below on your own risk. It’s recommended to test your solution in a development environment before applying in production.

 

pae

 

Here are some AD LDS examples that cannot be managed via PowerShell:

  • pae-CBRCEnable: boolean (optional, default true)
  • pae-CBRCCacheRefreshInterval
  • pae-CBRCCacheRefreshBlackout
  • pae-CBRCCachedDiskTypes
  • pae-VmOperationTimeout
  • pae-VmDampFactor
  • pae-VmProvSuspendOnError
The PowerShell function below can executed as is or as part of a module.
Set-ViewPoolState -IPAddress "127.0.0.1" -poolId "engineers-01" -property "pae-CBRCEnable" -state "1"

..

Function Set-ViewPoolState {
	Param (
		[parameter(ValueFromPipeline=$true,Position=0,Mandatory=$false)]
		[string]$IPAddress = "127.0.0.1",
		[parameter(ValueFromPipeline=$true,Position=1,Mandatory=$true)]
		[string]$poolId,
		[parameter(ValueFromPipeline=$true,Position=2,Mandatory=$true)]
		[string]$property,
		[parameter(ValueFromPipeline=$false,Position=3,Mandatory=$true)]
		[string]$state
	)

	$ldapBaseURL = 'LDAP://'+$IPAddress + ':389/'
	$objMachine = [ADSI]($ldapBaseURL + "cn=" + $poolId + ",ou=Server Groups,dc=vdi,dc=vmware,dc=int")
	$objMachine.put($property, $state)
	$objMachine.setinfo()

	if (!$?){
		Write-Log -Message $Error[0]
		Break
	} else {
		Write-Host "Setting pool state successful."
	}

	Return ""

 

Simply modifying $objMachine, as bellow, will allow you to interact with virtual desktop objects and gain access to many more AD LDS keys that control individual desktops. To make that happen just replace the line bellow on the main code and use the virtual desktop display name as PoolId.

 

$objMachine = [ADSI]($ldapBaseURL + "cn=" + $poolId + ",ou=Server,dc=vdi,dc=vmware,dc=int")

 

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

Similar Posts:

Permanent link to this article: http://myvirtualcloud.net/?p=4239

2 comments

  1. Mitja B.

    Not on a very high standard of the View PowerCLI cmdlets compared to vSphere PowerCLI. And there hasn’t been a single new cmdlet introducted since the first version. Such a shame having to do hacks like this to get things automated.

  2. Andre Leibovici

    @Mitja B.
    I hear you well and share similar sentiments about VMware View PowerCLI. Hopefully VMware will improve PowerCLI to get on pair with most VMware products.

    Andre

Leave a Reply