Waclaw Chrabaszcz
... there is no spoon ...

XenApp and XenDesktop 7.6 - connection leasing under the hood

Some time ago Citrix introduced XenDedexktop and XenApp version 7.6. One of key improvements, and the best one for me is the Connection Leasing. Lastly Citrix delivered any replacement for good old LHC (Local Host Cache). Since XD 7.0 to XenDasktop&XenApp 7.5 many admins refused to migrate into the most resent version due to lack of session sharing (all your apps within one ICA channel), session pre-launching ( 2000 users tries to logon at 9:00 AM J ) and lack of any database resilience mechanism. In old Xenapp 6.5 every servers (not in a worker mode) was able to store local copy of the data store, and in case of database absence, to use his local cache to launch requested application. Static data were stored in in this (small) database, where us all dynamic e.g. current load, were handled by Data Collectors.

After merging of XenApp with XenDesktop this situation became much more complicated. Tens of thousands VDI machines instead of hundreds of servers, tones of user to machine assignments and billions of state changes when machine is powered on or user just logged in. Database 7.x is very dynamic, because it plays the role not only of the DataStore but the DataCollector as well. Of course you can protect your database by SQL AlwaysOn, Mirroring, or Clustering, however even well protected database can collapse. And even if your database runs, your network might fails. In this case, all actives sessions remains, but no one new can launch the session, until the database will be back.

XenDesktop 7.6 introduces Connection Leasing … and XenApp it is just a different licensing model for the same product. Citrix not documented yet Connection Leasing, all we know is, that it is stored in some XML file. Connection Leasing is enabled by default, you can easy validate it using followed PoSH command:

If you would like to change default behavior you can disable/enable this feature:

Set-BrokerSite –ConnectionLeasingEnabled $false
Set-BrokerSite –ConnectionLeasingEnabled $true

Let's try to view current leases, we see two launch leases and one enumeration.

If we would like to update local data on demand we can execute:


But where really this data is stored in case of database absence?

In hidden folder c:\ProgramData\Citrix\Broker\Cache you will find followed folders:

Each of them stores some (pseudo-random?) folder and XML file with definitions of related Item. As an example I will present the Calc app.

Let's take a look on example enumeration of available resources for user on particular device (please keep in mind policy filters for the endpoint)

And an example application lease

We can find here when exactly this lease expires, after this date, in case of database failure, user will be unable to re-launch the app. Users and worker machine SID, based on it in case of DB failure user will be redirected to exactly the same worker, and I assume if any load evaluator is applied, there must be enough capacity for the new session. Session sharing key, yeah! Session sharing is really back! The last remaining question is: where is the information about the application delivered by this session. In my opinion it is hidden behind RSApps, but as you can see, there is no direct answer.

SCCM 2012 R2 and MDT – MDT Task Sequence

Today I'm going to create MDT Task Sequence in SCCM world. MDT offers advanced sequences, better prepared for customization and conditional installation. For example based on variables we can build accountant/developer specific workstation, with custom disk configuration, application sets, and much much more.

This time we will create a simple MDT Task Sequence to get familiar with MDT components. I would like to show as well few troubleshooting steps during the initial setup. I think it could be valuable for SCCM&MDT beginners.

  1. In the first step we will share MDT folder. We will create separate folder to demonstrate MDT package content and easy troubleshooting in the future.
  2. Let's create new MDT Task Sequence
  3. Client Task Sequence
  4. Task Sequence name
  5. We will join the domain
  6. We are not going to use this package for capturing new images
  7. Boot image – standard SCCM x64 boot
  8. In some specific situations you may be unable to create a new MDT package. Don't give up, we will fix it.
  9. troubleshooting: download and install/upgrade MDT 2013
  10. troubleshooting: Make sure your deployment share is created, more details how to configure it you can find in my previous post
  11. troubleshooting: Update Deployment Share
  12. troubleshooting: Let's optimize the boot image updating process

  13. Troubleshooting: After that unregister and register once again your MDT integration component in SCCM. Make sure your SCCM console is CLOSED during this operation
  14. Troubleshooting: ok, registration step – the wizard should detect your server site and the site code without issues
  15. Now the integration is fixed. You can start SCCM Admin Console and repeat steps since the beginning to the MDT package creation
    create the package using \\UNC-path to your MDT share, make subfolder for the package
  16. Package Details
  17. Image to Install – Windows 10 … not yet haha . As you can see, you can use this sequence for OS image creation.
  18. Of course Zero touch deployment
  19. Standard SCCM Client Package
  20. Standard USMT package
  21. MDT Settings package, once again we will store it on the MDT share in a separate subfolder
  22. Package details …. boring …. boring … boring
  23. Bye bye Windows XP and your SYSPREP, I will never forget you …
  24. Summary and go!
  25. Enjoy the progress bar
  26. Finish – Yuppie!!!


Let's check MDT packages content. There is something, and for MDT fanbois (if there are any) it looks familiar.


Ok Let's push this content to Distribution Points, coffee and we will try the installation.

SCCM, MDT and SCVMM – How to convert VHD into WIM

It is not possible. Due to obvious reasons, VHD is it a dynamic structure like a SQL database, whereas WIM is closer to ZIP file – very static and designed for conserving the storage space by compression and links to duplicated files.

What we can do else? We can capture VHD state to WIM. I'm going to perform this operation on Windows 7 machine, so unfortunately this time no PoSH commandlets like Mount-VHD. We will need imageX command, maybe you will need to download and install Windows AIK


Since we need to execute multiple DiskPart commands, we will have to rely on answer files:


diskpart /s attach.txt
imagex /compress maximum /check /scroll /boot /capture F: C:\TEMP\Win7.wim "Win7syspreped"
diskpart /s detach.txt


select vdisk file="C:\TEMP\Win7.vhd"
attach vdisk


select vdisk file="C:\TEMP\Win7.vhd"
detach vdisk

Now you can compare file sizes J

PowerShell – Sexy PoSH console

PowerShell don't has to be boring.

Download this module: http://www.powertheshell.com/download/modules/PTSAeroConsole.zip

Extract it into C:\Windows\System32\WindowsPowerShell\v1.0\Modules
(you may need to enable both module files by right clicking | Prosperities |Unlock)

Now you can start PowerShell window:


Import-Module PTSAeroConsole



AZURE - Stairway To Heaven


Before you’ll start reading please start to play this song.


OK boys and girls, time get familiar with clouds. Time to become a meteorologist. To be honest I don’t know how to start. Is cloud better or worse than on campus resources … hmm … it is just different. I think for successful adoption in cloud world IT Dinosaurs need to forget some “Private Cloud” virtualization bad habits, and learn new way of thinking.

Take a look:

- I don’t need any  tapes or  CDs  (Physical Kingdom of Windows XP and 2000)

- I don’t need any locally stored MP3s (CD virtualization :-)

- I can just stream music to your computer no matter whether my on-site infrastructure is powered on.

Why not to do exactly the same with WebServer, SQL, or just rented for a while Windows server ? Let’s go, to the other side of the mirror. 1st  - register yourself for free one month trial, as happy MSDN subscriber you’ve got monthly budget to spent. In addition in default setting your limit protects you against loosing real money, if your toys will consume too much traffic and space.


Once your account is ready forget WebPortal, we are PowerShell knights.


#Authenticate yourself in Azure

#download once your settings file

#Import it to your PowerShell Module
Import-AzurePublishSettingsFile "C:\Azure\[filename].publishsettings"


#where are Azure datacenters

#You will need it Smile

#storage account is related to physical location, there are two datacenters on each continent, try nearest to you
# all your VMs will store VHD files on your storage account
#your storage account must be unique globally, so I assume that words account or server are already used
New-AzureStorageAccount -StorageAccountName "[YOUR_STORAGE_ACCOUNT]" -Label "AzureTwo" -Location "West Europe"

#it looks like you are ready to deploy first VM, what templates we can use
Get-AzureVMImage | Select ImageName

#what a mess, let’s choose Server 2012
$ImageName = (Get-AzureVMImage)[74].ImageName

$cloudSvcName = '[YOUR_STORAGE_ACCOUNT]'
$AdminUsername = "[YOUR-ADMIN]"
$adminPassword = '[YOUR_PA$$W0RD]'
$MediaLocation = "West Europe"

$vmnameDC = 'DC01'

#burn baby burn !!!
$vmDC01 = New-AzureVMConfig -Name $vmnameDC -InstanceSize "Small" -ImageName $ImageName   `
    | Add-AzureProvisioningConfig -Windows -Password $adminPassword -AdminUsername $AdminUsername   `
    | New-AzureVM -ServiceName $cloudSvcName

#ice, ice baby …
Get-AzureRemoteDesktopFile -ServiceName "[YOUR_STORAGE_ACCOUNT]" -Name "DC01" -LocalPath "c:\AZURE\DC01.rdp"

As you can see it is not just a new-VM, you need to associate your VM with AzureVMConfig (it sets your template), AzureProvisioningConfig (it sets your customizations), and Storage account. In next releases you’ll need to put this machine in specific subnet, attach a HDD and many more. After second reading I found that I am using the same name for STORAGE and SERVICE account, please be aware of it if you need to split these values.

- pipe rules !
- at the beginning it is hard to change your mind and agree with fact that it is easier to remove and recreate a VM than move it to different subnet Smile
- by default everything is firewalled, limited access to DNS, but NATed outside on custom ports. It is good to check these translations sometimes on the webportal.
- if you remove your VMs your harddrives remains on storage and MS will charge you Smile. Remove-AzureVM -DeleteVHD

For me AZURE it is a lot of fun, once again I can be newbie and learn every page. For me Azure offers real freedom in deployment of VMs without arguing with NetAdmins, WinAdmins, DBAs, PMs and other Change Managers. Unfortunately soon or later they will come to my haven and change it into …


PowerShell – duplicated files in Windows Media Player library

Holiday! .. But why it's raining. Let's cleanup some duplicated MP3s. Maybe the rain will stop in the meantime.

For sure this code is not optimized, and I am not recommending anyone to use it. If you uncomment move actions you can reduce number of duplicated media files in your Windows Media Player library.

You can consider it as an example how to access and browse WMP using PowerShell.


$wmp = New-object –COM WMPlayer.OCX
$playlist = $wmp.mediaCollection.getAll()
do {
if ($playlist.item($i).sourceURL -like "*.mp3")
if ($playlist.item($i).name -eq $playlist.item($i-1).name)
write-host "n-1 : " $playlist.item($i-1).sourceURL
write-host $playlist.item($i).name " : " $playlist.item($i).sourceURL
if ($playlist.item($i).sourceURL.tostring().length -gt $playlist.item($i-1).sourceURL.tostring().length )
Write-Host -ForegroundColor yellow "moving " $playlist.item($i).sourceURL
#Move-Item $playlist.item($i).sourceURL "c:\output"
Write-Host -ForegroundColor red "moving " $playlist.item($i-1).sourceURL
#Move-Item $playlist.item($i-1).sourceURL "c:\output"
while ($i -le ($playlist.count -1))

Ahh .. A quick description, you've got media files in many folders. The script checks WMP library and in case of conflict wins the file with shorter URLpath. To move files uncomment #Move-Item. And let WMP rebuild library before next script run. It may take up to 3 days.

Server 2012 GUI – to be or not to be …

That's the question J

This quick post is inspired by one of feedbacks.

To enter into PowerShell just type powershell in CMD

To make Server 2012 core server:

Uninstall-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
Shutdown –r


To restore server's GUI


Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
Shutdown –r

Voila !

P.S. Of course it not works for 2008

Server 2012R2 – PowerShell Web Access

Haha … Sometimes I'm joking that there is nothing worse than Linux fanboi imprisoned in Windows engineer's body. Maybe someday I will start blogging about my noob's experiences. However let's stick to the point. Sometimes the easiest solutions are the best. After couple of tries how to reach left pocket using right hand I'm going to follow easy path. Today's plan is very easy, I'm going to take advantage of Server 2012 and install Web gateway to PowerShell console. After that I would be able execute PoSH from any device including Linux.

Install-WindowsFeature –Name WindowsPowerShellWebAccess –IncludeManagementTools
Install-PswaWebApplication –UseTestCertificate
Add-PswaAuthorizationRule –UserName * -ComputerName * -ConfigurationName *


Let's test it …


SQL 2012 – How to setup AlwaysOn cluster

As an application administrator, or transition engineer I need to store my data on some sort of database. Because SQL itself is not my primary focus I rather prefer "I don't care" solutions. It not means I don't care whether database is running or not. It mean I don't have enough time to become an expert in additional area to setup and understanding e.g. Log Shipping. What's more, it's not my problem only. I'll setup some SQL HA solution and walk away, whereas poor WinAdmin will RDP there day by day with heart palpitations.

Since SQL 2005 we've got two user friendly solutions, unfortunately each has a weak point.

  • SQL Cluster –needs a shared storage, in most cases expensive Enterprise class Disk array. And when we talk about DR scenario, we have to switch to remote location, as a result complexity and difficulty are growing very fast.
  • SQL Mirroring – for some reason not liked by many SQL admins (to be honest I would like to know why), and the weak point is limit to two nodes only.

Now with this background we can start to talk about SQL 2012 AlwaysOn. AlwaysOn thanks to mixing SQL and Server technologies removes mentioned limitations.

  • We can build cluster with more than two nodes – I think Windows Cluster (2008/1012) sets limit of nodes. In most of business cases you won't need more than 4-5 nodes. Only two of them works synchronously and can be failover automatically (HA), other are feed with data asynchronously (DR) and should be failed over manually. Good news, to not waist resources (and licenses) async nodes are not passive and you can use them for read only proposes e.g. reporting. Of course it can remove lot of load from primary production database.
  • We don't need any shared storage, what is huge advantage when we talk about Disaster Recovery scenarios.
  • My poor WinAdmin has his lovely right click tool J

In this exercise we will build typical SQL 2012 AlwaysOn Solution:

  • SQL-1 and SQL-2 will be High Availability pair in primary datacenter
  • SQL-2 will Disaster Recover in secondary DC, we will use SQL-3 for reporting proposes

Let's do it!

In first step on each node we will install cluster feature:

  1. In the second we will build Windows Custer using all nodes

    Read it carefully

    in production I would recommend you to use static IP address
  2. Now you can prepare each SQL instance for clustering

Make sure that both Replication Partners are added into each SQL users:

(an example for SQL-1)

use [master]

  1. We will need to make full backup of our database for initial replication. Use \\UNC\path\

  2. Eventually we can enable AlwaysOn on the database




Voila !

Easter egg – OMG^2 the true PowerShell in bash window

Let's continue this crazy experiment. More or less it should works on any distro in my case it is Ubuntu 13.

The idea is to use wine (Wine Is Not an Emulator J) to install Powershell 2.0 for Windows XP. Wine can emulate W7 or W8 however it refuses to install .MSU packages. To reach our goal we will need to use experimental wine 1.7 or above and EXE file so …

For the science!!!

sudo add-apt-repository ppa:ubuntu-wine/ppa
sudo apt-get update
sudo apt-get install wine1.7 winetricks
wget http://kegel.com/wine/winetricks
bash winetricks -q msxml3 dotnet35sp1
bash winetricks lucida
taskset -c 0 bash winetricks windowscodecs
wget -O ~/.cache/winetricks/WindowsXP-KB968930-x86-ENG/WindowsXP-KB968930-x86-ENG.exe http://download.microsoft.com/download/E/C/E/ECE99583-2003-455D-B681-68DB610B44A4/WindowsXP-KB968930-x86-ENG.exe
cd '~/.cache/winetricks/WindowsXP-KB968930-x86-ENG'
wine ./WindowsXP-KB968930-x86-ENG.exe

wine powershell

Happy Easter!