Horizon Instant Clones Fail to Join Domain?

3 min read
Horizon Instant Clones Fail to Join Domain?
VMware Horizon makes machines fast. Sometimes to fast.

The faster you go the more dangerous it can be. The same is true for VMware Horizon’s Instant Clone creation. Trust me it is amazing to see how fast Horizon through vSphere can create machines, its very impressive.

Lets me real though, sometimes things don’t work out. When working with over 7,000 VM’s across 9 Desktop Pools spanning 9 vCenters covering 2 geographically separated Data Center’s I’ve come to learn a thing or two about VMware Horizon’s processes.

Too Fast for Some

There was a time when doing roll outs that some Windows 10 VM’s created with Horizon Instant Clone would not join the domain. This was very rare over 7,000 machines it might be in the range of 25-50 VM’s.

Horizon Connection Brokers would still send users to these machines for login request. Greeting them with this message…

Now that the stage is set what should we do about it? When I ask this question I mean in the immediate, users are failing to login, service desk calls are coming in, people up the chain are starting to hear things. Immediate action is required. We can later debate why this is happening.

Domain Joined or Not | Shutdown

Below you’ll find the goods. This PowerShell file will accomplish the following:

  • Install and configure the modules needed for the Horizon connection
  • Get a list of Horizon Agent running machines that are in the status Available named either PC1 or PC2 in the beginning of their name (for 2 data centers). Remember this is only getting Available machines so it’ll skip Connected, Disconnected, and any other status so the number should be small.
  • Test each name to see if its joined to the domain. If it is not shut down the computer.

The shutdown will be affective since Horizon Instant Clone is designed to delete powered off machines and create them anew. The new machine should join the domain successfully and be good for new connections.

Best Regards
Michael Wood


#--- Install & Configure Modules ---

$ErrorActionPreference = 'silentlycontinue'
Install-Module VMware.PowerCLI -Scope CurrentUser
Set-PowerCLIConfiguration -ParticipateInCeip $False -Scope User
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope User -Confirm:$False
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope User -Confirm:$False
Get-Module -ListAvailable VMware* | Import-Module
Connect-HVServer -Server horizonconnectionbroker.company.com

$Services1=$Global:DefaultHVServers.ExtensionData
$AvailableVMMD1s = Get-HVMachineSummary -State AVAILABLE -MachineName PC1* | Select -ExpandProperty Base | Select -ExpandProperty Name
$AvailableVMMD2s = Get-HVMachineSummary -State AVAILABLE -MachineName PC2* | Select -ExpandProperty Base | Select -ExpandProperty Name


#---------------Display Banner--------------------

CLS
Write-Host "Locating list of Computers..." -ForegroundColor Yellow
$AvailableVMMD1s
$AvailableVMMD2s
Write-Host ""
Write-Host "Are you part of a Domain?" -Foreground Cyan
Read-Host "Press Enter to begin running the request"
Write-Host ""
Write-Host " ════════ " -NoNewLine
Write-Host "RESULTS " -Foreground Cyan -NoNewLine
Write-Host "════════"



#---------------Variables-------------------------

$StartTime = Get-Date -format "yyyyMMddThhmmss"
$StartTime


#----------------Application1----------------------

Foreach ($AvailableVMMD1 in $AvailableVMMD1s) {

Write-Host "$AvailableVMMD1 - " -Foreground Green -NoNewline

    $Domain = Invoke-Command -ComputerName $AvailableVMMD1 -ScriptBlock {(gwmi win32_computersystem).partofdomain}
    
    If ($Domain -eq "True") {
    Write-Host "$Domain" -Foreground Yellow
    }

    Else {
    Stop-Computer -ComputerName $AvailableVMMD1
    $Logfile = "\\uncpath\DomainJoinedorNotShutdowns.txt"
    $GetDate = Get-Date -format "yyyyMMddThhmmss"
    Add-Content -Path $LogFile -Value "$GetDate - $AvailableVMMD1 - Off Domain!"
    Write-Host "False" -ForegroundColor Red
    }

}


#----------------Application2----------------------

Foreach ($AvailableVMMD2 in $AvailableVMMD2s) {

Write-Host "$AvailableVMMD2 - " -Foreground Green -NoNewline

    $Domain = Invoke-Command -ComputerName $AvailableVMMD2 -ScriptBlock {(gwmi win32_computersystem).partofdomain}
    
    If ($Domain -eq "True") {
    Write-Host "$Domain" -Foreground Yellow}

    Else {
    Stop-Computer -ComputerName $AvailableVMMD2
    $Logfile = "\\uncpath\DomainJoinedorNotShutdowns.txt"
    $GetDate = Get-Date -format "yyyyMMddThhmmss"
    Add-Content -Path $LogFile -Value "$GetDate - $AvailableVMMD2 - Off Domain!"
    Write-Host "False" -ForegroundColor Red
    }

}


#---------------Good Bye Message---------------

$FinishTime = Get-Date

Write-Host ""
Write-Host " ═══════════════════════════════ " -NoNewLine
Write-Host "TEMPLATE " -Foreground Cyan -NoNewLine
Write-Host "════════════════════════════════════"
Write-Host ""
Write-Host -ForegroundColor Green "Completed!"
Write-Host ""
Write-Host -ForegroundColor Cyan "Start Time:"
Write-Host "$StartTime"
Write-Host ""
Write-Host -ForegroundColor Cyan "Finish Time:"
Write-Host "$FinishTime"
Write-Host ""
Read-Host "Press any key to exit application"

Start-Process "\\uncpath\DomainJoinedorNotShutdowns.txt"
Virtualize Brief


Follow