Citrix · XenDesktop 7

Automate cleaning up RemotePC catalog

have the RemotePC catalog setup to monitor OU’s.  So as soon as the software gets installed it automatically gets added to the machine catalog.  But in XenDesktop 7.x there is no way to cleanup old machines.  I created a powershell script that will remove the machines from the machine catalog and the Desktop Group.  Both of them are named RemotePC in my environment.

If the computers have not communicated in 45 days it removes them.  If they do come back online they will get automatically added back since I am monitoring the OU’s.

asnp citrix*

$ts = New-TimeSpan -Days -400
$a = Get-Date
$b = (get-date) + $ts
$machines = Get-BrokerMachine -DesktopGroupName RemotePC
foreach($d in $machines)
{
if($d.LastDeregistrationTime -le $b)
{
$d.SID+"      "+$d.LastDeregistrationTime
write-host $d.MachineName

#comment the items out below to see how many you will delete before you run it.
$dl = $D.MachineName
$dl = Get-BrokerMachine -MachineName $d.MachineName
$dl | Set-brokermachinemaintenanceMode -MaintenanceMode $true
$dl | Remove-BrokerMachine -DesktopGroup RemotePC -Force
$dl | Remove-BrokerMachine -Force

}
}



-TG

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s