VMware Horizon Community
Lyghtnin
Enthusiast
Enthusiast

Looking for a script to remove VMs (Not delete)

As the subject says - I'm looking for a script to remove vms from Horizon View Mgmt.

After much research I've hit a brick wall as the PowerCLI does nto have this cmdlet so I need an alternate way of doing this

Thanks in advance!

Reply
0 Kudos
4 Replies
jrodsguitar
Enthusiast
Enthusiast

Please explain what you want to do. You don’t want to delete a Vm from Horizon but you want to remove it. Does that mean you still want to keep the VM but remove it from being managed by Horizon?

Blog: https://powershell.house/
Reply
0 Kudos
Lyghtnin
Enthusiast
Enthusiast

That's exactly what I need.

Horizon View Management Console is just managing the desktops IN vCenter. I want to remove the desktop from the Horizon View pool in the management console but not delete it from vCenter.

Reason - Users have a full clone and when they leave the company we want to be able to retain the desktop for 45 days in vCenter (powered off) but not have it listed in the Horizon View Pool any longer. We currently have it automated to mark custom attributes in the VM and power it off and moved to a specific folder in vCenter, we just need to be able to remove it from Horizon with an automated process/script to complete the task. (We do not have vRO/vRA).

Thanks for the reply!

Reply
0 Kudos
jrodsguitar
Enthusiast
Enthusiast

I think one way to do this is to:

  1. Clone existing VM to new VM
  2. Remove / Delete original VM from Horizon
  3. Remove Horizon Agent from new cloned VM.

Since you  are already using automation, you could probably incorporate some of the code from my remove-HVMachine function to accomplish step 2.

So ironically you will end up deleting VM. At least the original Smiley Happy

https://get-cj.com/2018/04/07/delete-vmware-horizon-machine-using-powercli-horizon-api/

It's very straight forward to use:

remove-HVMachine -cred $cred -viewserver $viewserver -machine $machine

Blog: https://powershell.house/
Reply
0 Kudos
butlpau02
Contributor
Contributor

Hey,

How are your desktops provisioned?  Manual, Linked Clones etc?

Have you looked at ADSIEDIT to do this - depending on how desktops are provisioned, you may have to change Pool sizes etc so they are not recreated etc....

Cheers,

Paul.

Reply
0 Kudos