VMware Cloud Community
imtrinity94
Enthusiast
Enthusiast
Jump to solution

Workflow Needed: Rebuild a VM in Horizon Full-Clone Desktop Pool

Hi 

I was trying to build a workflow for rebuilding a desktop/virtual machine for full-clone desktop pool. VMware article here mentions that 

"

When you rebuild a virtual machine, the virtual machine is deleted and then cloned with the same virtual machine name and the AD computer accounts are reused. All user data or settings from the previous virtual machine are lost and the new virtual machine is created using the desktop pool template.

"

I am trying to achieve the same using a workflow. What I did in Workflow is: 

imtrinity94_0-1637732158243.png

Getting the same customizationSpec and Template from vSphere and start the cloning process with exact details. However, the machine then created doesn't register itself in Horizon Pool. Any suggestions what can i do here? 


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
Tags (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
imtrinity94
Enthusiast
Enthusiast
Jump to solution

2.) After everything is setup, try to reset a machine using Reset-HVMachine to check setup is fully functional.
3.) Run this PS command in PowerShell ISE
function Rebuild-HVMachine {
  <#
  .Synopsis
     Rebuilds Horizon View desktops.
  .DESCRIPTION
     Queries and rebuilds virtual machines (create new cloned VM with same name from same template and applies same customization specification), the machines list would be determined
     based on queryable fields machineName. Use an asterisk (*) as wildcard. If the result has multiple machines all will be reset.
     Please note that on an Instant Clone Pool this will do the same as a recover of the machine.
  .PARAMETER MachineName
     The name of the Machine(s) to query for.
     This is a required value.
  .PARAMETER HvServer
    Reference to Horizon View Server to query the virtual machines from. If the value is not passed or null then
    first element from global:DefaultHVServers would be considered in-place of hvServer
  .EXAMPLE
     rebuild-HVMachine -MachineName 'PowerCLIVM'
     Queries VM(s) with given parameter machineName
  .EXAMPLE
     rebuild-HVMachine -MachineName 'PowerCLIVM*'
     Queries VM(s) with given parameter machinename with wildcard character *
  .NOTES
    Author                      : Mayank Goyal
    Author email                : mayankgoyalmax@gmail.com
    Version                     : 1.0
    ===Tested Against Environment====
    Horizon View Server Version : 7.3.0
  #>

  <#
  [CmdletBinding(
  SupportsShouldProcess = $true,
  ConfirmImpact = 'High'
  )]
  #>

  param(

  [Parameter(Mandatory = $true)]
  [string]
  $MachineName,

  [Parameter(Mandatory = $false)]
  $HvServer = $null
  )

  Begin {

    $services = Get-ViewAPIService -hvServer $hvServer

    if ($null -eq $services) {
      Write-Error "Could not retrieve ViewApi services from connection object"
      break
    }

    $machineList = Find-HVMachine -Param $PSBoundParameters

    if (!$machineList) {
      Write-Host "Rebuild-HVMachine: No Virtual Machine(s) Found with given search parameters"
      break
    }
  }
  Process {
    if ($Force -or $PSCmdlet.ShouldProcess($MachineName)) {
      foreach ($machine in $machinelist){
        $services.machine.Machine_RebuildMachines($machine.id)
      }
    }
  }
  End {
    [System.gc]::collect()
  }
}
4.) Call this function in this format Rebuild-HVMachine -MachineName 'machineName'

Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/

View solution in original post

Reply
0 Kudos
3 Replies
eoinbyrne
Expert
Expert
Jump to solution

Hi

Looking at your image there I can't help notice one problem (always suggest the simplest fix first is a personal maxim so no insult intended here 😊)

In your screengrab, the workflow does not execute the "Add unmanaged Machine" workflow at all? The script step "Prepare inputs for..." just runs directly to the "Stop Workflow" icon so that's what will happen 

eoinbyrne_0-1637754828949.png

As I say, if you're already done this, please ignore me 😉

-HTH

Reply
0 Kudos
imtrinity94
Enthusiast
Enthusiast
Jump to solution

Thanks for reply and suggestion. Yes I have already tried that. Thing is this workflow can only add Machines to a Manual Desktop Pool and in my case the pool type is Full-Clone Automated Desktop Pool. That's the reason its sideways now.


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
Tags (1)
Reply
0 Kudos
imtrinity94
Enthusiast
Enthusiast
Jump to solution

2.) After everything is setup, try to reset a machine using Reset-HVMachine to check setup is fully functional.
3.) Run this PS command in PowerShell ISE
function Rebuild-HVMachine {
  <#
  .Synopsis
     Rebuilds Horizon View desktops.
  .DESCRIPTION
     Queries and rebuilds virtual machines (create new cloned VM with same name from same template and applies same customization specification), the machines list would be determined
     based on queryable fields machineName. Use an asterisk (*) as wildcard. If the result has multiple machines all will be reset.
     Please note that on an Instant Clone Pool this will do the same as a recover of the machine.
  .PARAMETER MachineName
     The name of the Machine(s) to query for.
     This is a required value.
  .PARAMETER HvServer
    Reference to Horizon View Server to query the virtual machines from. If the value is not passed or null then
    first element from global:DefaultHVServers would be considered in-place of hvServer
  .EXAMPLE
     rebuild-HVMachine -MachineName 'PowerCLIVM'
     Queries VM(s) with given parameter machineName
  .EXAMPLE
     rebuild-HVMachine -MachineName 'PowerCLIVM*'
     Queries VM(s) with given parameter machinename with wildcard character *
  .NOTES
    Author                      : Mayank Goyal
    Author email                : mayankgoyalmax@gmail.com
    Version                     : 1.0
    ===Tested Against Environment====
    Horizon View Server Version : 7.3.0
  #>

  <#
  [CmdletBinding(
  SupportsShouldProcess = $true,
  ConfirmImpact = 'High'
  )]
  #>

  param(

  [Parameter(Mandatory = $true)]
  [string]
  $MachineName,

  [Parameter(Mandatory = $false)]
  $HvServer = $null
  )

  Begin {

    $services = Get-ViewAPIService -hvServer $hvServer

    if ($null -eq $services) {
      Write-Error "Could not retrieve ViewApi services from connection object"
      break
    }

    $machineList = Find-HVMachine -Param $PSBoundParameters

    if (!$machineList) {
      Write-Host "Rebuild-HVMachine: No Virtual Machine(s) Found with given search parameters"
      break
    }
  }
  Process {
    if ($Force -or $PSCmdlet.ShouldProcess($MachineName)) {
      foreach ($machine in $machinelist){
        $services.machine.Machine_RebuildMachines($machine.id)
      }
    }
  }
  End {
    [System.gc]::collect()
  }
}
4.) Call this function in this format Rebuild-HVMachine -MachineName 'machineName'

Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
Reply
0 Kudos