6.2

Table Of Contents
Script Input
The input file is of type csv and contains the names of the machines to be deleted. The following example
shows what the input file may contain.
MachineName
linux-001
linux-002
linux-003
The sample script assumes that the name of this input file is DeleteMachineItems.csv and that the file is
located in the same folder as the scripts.
Script Content
<#
bulk Delete registered machine items from broker LDAP database.
#>
$csvFile = '.\DeleteMachineItems.csv'
#check if file exists
if (!(Test-Path $csvFile))
{
write-host -ForeGroundColor Red "CSV File $CSVFile not found"
exit
}
function IsNameInCsv($name)
{
$csvData = Import-CSV $csvFile;
foreach ($line in $csvData)
{
if($line.MachineName -eq $name)
{
Write-Host "$name exists in csv"
return $true;
}
}
Write-Host "$name does not exists in csv"
return $false;
}
$obj = [adsi]'LDAP://localhost:389/OU=Servers,DC=vdi,DC=vmware,DC=int';
foreach ($child in $obj.psbase.Children)
{
$machineName = $child.get("pae-DisplayName");
if(IsNameInCsv($machineName))
{
$machineAttributes = $child | get-member;
$machineAttributes = $machineAttributes -join ' ';
if ($machineAttributes -like "*pae-MemberDNOf*")
{
$desktopPool = $child.get("pae-MemberDNOf");
Write-Host "Skip $machineName, which is included by desktop pool $desktopPool";
Chapter 3 Bulk Deployment of Horizon 6 for Linux Desktops
VMware, Inc. 51