Archive for the 'Citrix' Category

Script to fix “unknown” power state in Xen Desktop


After an unpretty Hyper-V cluster failover, several machines in our Xen Desktop deployment were showing an “unknown” power state.  After a call to Citrix, they gave my coworker a few commands to use to fix it.

This has to be done from the Xen Desktop controller:

Load the Citrix PSSnapIn:

Add-PSSnapIn Citrix.*

This gets information from VMM about all of the VMs in VMM:

Cd XDHyp:\
Get-ChildItem -recurse | Out-File –Filepath c:\xdhyp.txt

This command gets all of the machines that are PowerState Unknown in Xen Destkop:

Get-BrokerMachine -PowerState Unknown

The problem is that the “Id” from the first command doesn’t match the “HostedMachineId” from the second command.  To fix this, you run this command with the correct domain and machine name from the second command and the  “Id” from the first command:

Set-BrokerMachine -MachineName <MyDomain\MyMachine> -HostedMachineId <Id>

You have a lot of machines where this is a problem, it could take a while to go through and match these up.  To save some time with the 75 or so we had to do, created this script to do it:

#Add-PSSnapIn Citrix.*

$x = 0
$UnknownList = Get-BrokerMachine -PowerState Unknown
# HostedMachineId          : 51c7f7a2-64bf-481a-86fd-49b9a3fbf993
# MachineName              : Domain\MachineName
foreach ($_ in $UnknownList)
        $UnknownMachine = $_
        Write-Host $_.MachineName
        $UnknownMachineName = $_.MachineName
        #trim the domain to search
        $SearchName = $UnknownMachineName.TrimStart("<domain>\")
        Write-Host "Search Name is $SearchName"
        $Group =  "XDHyp:\Connections\<VMMSERVER>\<Vmmhostgroupname>.hostgroup\<clustername>.cluster"
        $GroupList = Get-ChildItem $VDCB | Where-Object {$_.Name -match $SearchName}
        # Name    : MachineName
        # Id    : 8d9d4e54-d374-406b-b4e3-7dcd2f47e7a9
        foreach ($_ in $GroupList)
                $x ++
                Write-Host $_.Name
                $HostedMachineId = $_.Id
                Write-Host $HostedMachineId
        Write-Host $x
        set-BrokerMachine -MachineName $UnknownMachineName -HostedMachineId $HostedMachineId

Citrix Worker Groups

Lately, we have been deploying XenApp servers using Citrix Provisioning Services.  This is a great tool, that we have only just started using. 

In our current process, we are creating a group of machines using PVS.  When they come up, the join the farm and by virtue of the AD OU they are in, they become members of a worker group.  We are also creating machines for test purposes that we want to get the same Group Policies, but we don’t want them to be in the worker group by default.  We deploy the production apps to the Worker Groups, but not to individual machines.  If the test machines are part of the Worker Groups, then the apps are also published to the test machines. 

To prevent this, we created a sub OU to put the particular test machines in, so they would get the Group Policies, but not have the apps automatically published to them.  Except that the machines wouldn’t come out of the Worker Group…

Turns out, if the machines joined the farm in the OU that the Worker Group is looking at, they will remain in the worker group.  In order to correct this, you simply remove the offending machines from the farm.  When they come back up and join the farm again, they are no longer part of the worker group.  (As long as the machine accounts aren’t in the target OU.)

Launch a PowerShell script minimized

We use Citrix for a lot of applications, and I have a need to launch Outlook, then an application, and then close Outlook when that application is closed by the user.  This seems like a pretty simple thing to do (and I suppose it is, sort of) but it took me a while to figure it out. 

One piece of the puzzle is that PowerShell remains open if you do it the way I have it setup right now.  If the user closes that PowerShell window, then the monitor process will not close Outlook when the user exits the LOB app.  In order to mitigate this issue somewhat, I wanted to start PowerShell minimized.  The way to do this is:

powershell -WindowStyle Minimized .\ScriptToRun.ps1

Unable to login to Citrix server via RDP or ICA

We have recently set up some new Windows Server 2008 R2/Citrix XenApp 6.0 servers.  For some reason, users could not launch a remote desktop to them even though we (thought) allowed this.  Turns out there is a policy which blocks this by default.  I found the answer here:

Re: Unable to login using RDP or ICA after installing XenApp 6
Posted: Mar 31, 2010 5:27 PM   in response to: Aref  Mukred in response to: Aref Mukred


This message was useful
4 users found this post useful

Hi Aref –
Can you please try the following ?
1. Open Delivery Services Console
2. Edit the unfiltered user policy | ICA
3. Set the policy for Desktop Launches to Allowed
This policy applies to XenApp 6.0 and Allows or prevents non-administrative users to connect to a desktop session on the server.
When allowed, non-administrative users can connect. By default, non-administrative users cannot connect to desktop sessions.

Citrix Forums : Unable to login using RDP or ICA after …

The answer above will get you there, but as my teachers used to tell me all the time, he needs to “show his work”: