vCO Workflow Script to Remove All Computer Accounts from an OU in Active Directory using the Microsoft AD Plugin

The following script removes all computer accounts from an organisational unit in active directory using the Microsoft AD plugin

 

 

var arrOrganizationalUnits;
	arrOrganizationalUnits = objOrganizationalUnitParent.organizationalUnits;

var objOrganizationalUnit;
	objOrganizationalUnit = null;

for (var i in arrOrganizationalUnits)
{
	if (arrOrganizationalUnits[i].name == "Organizational-Unit-Name")
 {
 objOrganizationalUnit = arrOrganizationalUnits[i];
 }
}

var arrComputersAD;
 arrComputersAD = objOrganizationalUnit.computers;

System.log("==================================================");

for (var objComputerAD in arrComputersAD)
{
 if ( arrComputersAD[objComputerAD].name == "" )
 {
 var objRemoveComputerAD;
 objRemoveComputerAD = arrComputersAD[objComputerAD];
 objRemoveComputerAD.destroy();

 System.warn("===== ComputerAD Deleted: " + objRemoveComputerAD.name);
 }
}

objOrganizationalUnit = null;

var arrOrganizationalUnits;
 arrOrganizationalUnits = objOrganizationalUnitParent.organizationalUnits;

for (var i in arrOrganizationalUnits)
{
 if (arrOrganizationalUnits[i].name == "Cloud")
 {
 objOrganizationalUnit = arrOrganizationalUnits[i];
 }
}

var arrComputersAD;
 arrComputersAD = objOrganizationalUnit.computers;

System.log("==================================================");

for (var objComputerAD in arrComputersAD)
{
 System.log("objComputerAD.name = " + arrComputersAD[objComputerAD].name);
}

System.log("==================================================");

Leave a Reply