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


  1. The $VDCB line should have been written as:
    $GroupList = Get-ChildItem $Group| Where-Object {$_.Name -match $SearchName}

    VDCB was the cluster name that I used in production. I apologize for the confusion.

  2. I went through this process only to find that all of the IDs matched in both places.
    So I called Citrix. They had me restart the Citrix Host service on the DDCs. No dice. We ran the commands again and they still matched. We restarted the VMs again with no issue. They decided to transfer me to XenApp team. While on hold I scanned the article for XenDesktop 5:
    At the bottom it recommends restarting the Broker service on the DDCs (mind you they said and/or the Vmms having the issue which we had previously done). That did the trick. All of the systems came up a powerstate On. It’s crazy how many dependencies xen desktop has.

    Also, fun fact: If your delivery group only has one server in it, regardless of the powerstate showing as unknown sessions will be brokered to it. If you have one or more: Nope.

  3. I had a similar issue but it was pool wide, what it ended up being was the Host connection in Studio, I just reset the password and all was good. Its slightly different from the issue above but showed the same symptoms, machines power state was unknown. But it was the entire Pool.

  4. Hello,

    Very helpful stuff, by script we were pulling HostedMachineId (MoRef) from VMware and in the end filling in 2 values, to have something like this:
    Get-BrokerMachine -PowerState Unknown | ft -a MachineName,HostedMachineId
    MachineName HostedMachineId
    ———– —————
    Domain\MachineName 4214ae0b-81c4-d34b-5de8-3c90ec28c46b 4211a35e-b45a-a7e8-7a09-b5b0f1745402

    Your article has helped us to modify the script. Beware, it’s possible to create a VDI with 2 HostedMachineId and then the above (PowerState Unknown) can occur as well.
    Thanks for sharing!

  5. Hi nice script.. what is we have multiple VMserver to check. can we write comma seperated

  6. HI Nice Script.. but it executes till the machine namea and search machine name.

    the last loop is running but the value is always 0

    is there anything that we need to modify on this script.

  7. i had same issue, So i just restarted Broker services on all the controller, and all the vdi power state showed up.

Leave a Reply