Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## 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
- ## Requires the PowerCLI and AD PowerShell modules.
- ## Use at your own risk
- Connect-VIserver yourvcenter
- 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