{"id":308,"date":"2012-08-27T09:02:54","date_gmt":"2012-08-27T14:02:54","guid":{"rendered":"http:\/\/nukeitmike.com\/blog\/?p=308"},"modified":"2012-08-27T09:02:54","modified_gmt":"2012-08-27T14:02:54","slug":"script-to-fix-unknown-power-state-in-xen-desktop","status":"publish","type":"post","link":"https:\/\/blog.nukeitmike.com\/index.php\/2012\/08\/27\/script-to-fix-unknown-power-state-in-xen-desktop\/","title":{"rendered":"Script to fix \u201cunknown\u201d power state in Xen Desktop"},"content":{"rendered":"<p>&#160;<\/p>\n<p>After an unpretty Hyper-V cluster failover, several machines in our Xen Desktop deployment were showing an \u201cunknown\u201d power state.&#160; After a call to Citrix, they gave my coworker a few commands to use to fix it. <\/p>\n<p>This has to be done from the Xen Desktop controller:<\/p>\n<p>Load the Citrix PSSnapIn:<\/p>\n<blockquote>\n<p>Add-PSSnapIn Citrix.*<\/p>\n<\/blockquote>\n<p>This gets information from VMM about all of the VMs in VMM:<\/p>\n<blockquote>\n<p>Cd XDHyp:\\     <br \/>Get-ChildItem -recurse | Out-File \u2013Filepath c:\\xdhyp.txt<\/p>\n<\/blockquote>\n<p>This command gets all of the machines that are PowerState Unknown in Xen Destkop:<\/p>\n<blockquote>\n<p>Get-BrokerMachine -PowerState Unknown<\/p>\n<\/blockquote>\n<p>The problem is that the \u201cId\u201d from the first command doesn\u2019t match the \u201cHostedMachineId\u201d from the second command.&#160; To fix this, you run this command with the correct domain and machine name from the second command and the&#160; \u201cId\u201d from the first command:<\/p>\n<blockquote>\n<p>Set-BrokerMachine -MachineName &lt;MyDomain\\MyMachine&gt; -HostedMachineId &lt;Id&gt;<\/p>\n<\/blockquote>\n<p>You have a lot of machines where this is a problem, it could take a while to go through and match these up.&#160; To save some time with the 75 or so we had to do, created this script to do it:<\/p>\n<blockquote>\n<p>#Add-PSSnapIn Citrix.*     <br \/>#$ErrorActionPreference=Continue<\/p>\n<p>$x = 0     <br \/>$UnknownList = Get-BrokerMachine -PowerState Unknown      <br \/># HostedMachineId&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : 51c7f7a2-64bf-481a-86fd-49b9a3fbf993      <br \/># MachineName&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : Domain\\MachineName      <br \/>foreach ($_ in $UnknownList)      <br \/>&#160;&#160;&#160; {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $UnknownMachine = $_      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host $_.MachineName      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $UnknownMachineName = $_.MachineName      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; #trim the domain to search      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $SearchName = $UnknownMachineName.TrimStart(&quot;&lt;domain&gt;\\&quot;)      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host &quot;Search Name is $SearchName&quot;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $Group =&#160; &quot;XDHyp:\\Connections\\&lt;VMMSERVER&gt;\\&lt;Vmmhostgroupname&gt;.hostgroup\\&lt;clustername&gt;.cluster&quot;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $GroupList = Get-ChildItem $VDCB | Where-Object {$_.Name -match $SearchName}       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; # Name&#160;&#160;&#160; : MachineName      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; # Id&#160;&#160;&#160; : 8d9d4e54-d374-406b-b4e3-7dcd2f47e7a9      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; foreach ($_ in $GroupList)      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $x ++      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host $_.Name      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $HostedMachineId = $_.Id      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host $HostedMachineId      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Write-Host $x      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; set-BrokerMachine -MachineName $UnknownMachineName -HostedMachineId $HostedMachineId      <br \/>&#160;&#160;&#160; }<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>&#160; After an unpretty Hyper-V cluster failover, several machines in our Xen Desktop deployment were showing an \u201cunknown\u201d power state.&#160; 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&hellip; <a class=\"more-link\" href=\"https:\/\/blog.nukeitmike.com\/index.php\/2012\/08\/27\/script-to-fix-unknown-power-state-in-xen-desktop\/\">Continue reading <span class=\"screen-reader-text\">Script to fix \u201cunknown\u201d power state in Xen Desktop<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,25,26],"tags":[62,135,154,190,200],"class_list":["post-308","post","type-post","status-publish","format-standard","hentry","category-citrix","category-scripting","category-scvmm","tag-citrix","tag-powershell","tag-scripting","tag-vmm","tag-xendesktop","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pcW544-4Y","_links":{"self":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":0,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/308\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/media?parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/categories?post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/tags?post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}