1 person found this helpful
The example script from the blog post announcing powercli 6.5 does just that. Only thing you might need to change is the restart-vmguest to reset or whatever you want.
Thank you, Magneet, for this information. However, I tried it on my problem machines "Agent_Unreachable", and restarting the VM in vCenter didn't do the trick (which is what the script did).
I really need access to Horizon-View commands like Refresh and Remove that would not have a vCenter equivalent. I suspect they would be found in the "View API", but it is a mystery to me. I don't know how to take what I'm finding on the API website and translate it to PowerShell.
How do I Refresh or Remove problem vms in Horizon 7 using PowerShell?
There are multiple ways but delete desktop works better since refresh would be to nice and might fail if the agent refuses. I will get back to you about this, what would you prefer to get a list with desktops in a non-standard state and give you the option the remove the ones you want removed (my preference) or blindly delete them all (easier since I can largely re-use that example script above). They only issue I currently have is that get-hvmachine doesn't go above 1000 vdi's. I have created a workaround but that's not the best coding yet
Thank you for offering to write a script for this, Magneet. I'm sure the whole community could benefit from this operation.
My thought is that the script searches for machines in a problem state, and then it Removes them. My goal is to have this running without user intervention, as a scheduled task. So that's your second option.
P.S. There are over 1000 desktops in my View environment.
1 person found this helpful
I have created a script and posted it on my github, I will probably do a blogpost about it next week
This scripts asks for the connections erver, credentials after that it asks the state it wants to pull all desktops for that state (max results is 1000 at this point). Then it will ask about what desktop to remove and removes it. The error states are some of the most common ones but can be expanded easily.
This is a fabulous script, and I have used it successfully in my environment. Thank you, Magneet!
I just wanted to point out that this is where I was stuck and have now learned what to do in future scripts that involve the Horizon API. Here is a little of Magneet's code:
$spec = New-Object VMware.Hv.machinedeletespec
Thanks again! Now if this could just come standard in Horizon PowerShell module!
I have to be honest that that $spec part has costed me at least 3 hours before i figured it out that it needed to be there even though it defaults to what I wanted already. The 1000 vm limit is really for the results part so you would need to have over 1000 vm's in that state before it hits that max and when you cleared those 1000 it will use the next 1000.
For a scheduled task you could get all the id's for the machines and use the machine_deletemachines method since that method should havent tested it yet accept multiple machine id's from an array. the hardest part for a scheduled task is almost the authentication part since the horizon part doesn't accept current credentials yet nor has it a hvcredentialstore item. For the Horizon vcheck I have used an encrypted file with only the password in it