Advertisement
guyrleech

Find & Remove non-existent Horizon Instant Clone AD computer objects

Jan 31st, 2025
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 0.68 KB | Software | 0 0
  1. ## Find and remove all AD computer objects named it* that are from VMware/Omnissa Horizon instant clone VMs but the vSphere template for them no longer exists
  2. ## Requires the PowerCLI and AD PowerShell modules.
  3. ## Use at your own risk
  4.  
  5. Connect-VIserver yourvcenter
  6.  
  7. get-adcomputer -Filter "name -like 'it*'" -Properties Description|select Name,@{n='Template';e={ if( $_.Description -match 'Can be deleted if vm (\S*) does not exist in the VC' ) { $script:template = $matches[1] ; $script:template} }},@{n='VM';e={Get-VM $script:template -EA 0}},@{n='ADObject';e={$_}}|where VM -eq $null -PipelineVariable computer |ForEach-Object { $computer.Name ; Remove-ADObject -Identity $computer.ADObject }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement