VMware Cloud Community
BillStreet00
Enthusiast
Enthusiast
Jump to solution

OOTB - Destroy A Computer

As part of my retirement process, I want to remove the VM from AD. I created a WF with a scriptable task in which I pass the VM name and convert it to an AD:ComputerAD object and attempt to pass that variable to the OOTB Destroy a Computer WF.

The script is pretty simple.

var machine = payload.get("machine") ;

var vCACVmProperties = machine.get("properties") ;

var vm = machine.get("name");

computer = ActiveDirectory.getComputerADRecursively(vm);

System.log("Computer count: "+computer.length);

for each (pc in computer){

System.log("Checking computer: "+pc.name);

    if (vm.toLowerCase() == pc.name.toLowerCase()){

    System.log("Found Computer: "+pc.name);

    }

}

pastedImage_0.png

pastedImage_1.png

When the WF is executed I end up with a Bad Syntax 'Array" error.

[2017-10-05 08:28:28.089] [I] Computer count: 1

[2017-10-05 08:28:28.090] [I] Checking computer: XXXX

[2017-10-05 08:28:28.091] [I] Found Computer: XXXX

[2017-10-05 08:28:28.092] [I] Computer Object:  DynamicWrapper (Instance) : [AD_Computer]-[class ch.dunes.ad.object.Computer] -- VALUE : #_v2_#,#Computer#,#012827d2-77fb-435f-bf6e-8fff3fcf4e76#,#CN=XXXX,OU=XXXX,OU=XXXX,OU=XXXX,DC=XXXX,DC=XXXX#

[2017-10-05 08:28:28.093] [I] Retiring:  XXXX

[2017-10-05 08:28:28.095] [E] Workflow:Retire Server v2 / Scriptable task (item1) : ch.dunes.model.type.ConvertorException: Unable to convert object, '[Ljava.lang.Object;@7a9c14c9' plugin unexcepted exception : Bad type syntax 'Array'

[2017-10-05 08:28:28.122] [E] Workflow execution stack:

***

item: 'Retire Server v2/item1', state: 'failed', business state: 'null', exception: 'Unable to convert object, '[Ljava.lang.Object;@7a9c14c9' plugin unexcepted exception : Bad type syntax 'Array''

workflow: 'Retire Server v2' (98ada173-7bf4-485f-aeb0-5a893c34eef4)

|  'attribute': name=computer type=AD:ComputerAD value=__NULL__

Has anyone experienced this error before?

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

ActiveDirectory.getComputerADRecursively(vm) returns an array of computers, but you are assigning it to a variable computer which is not an array but singular object. What you need is to store the array of computers into a new variable, and then lookup your target machine inside it and assign this single machine (if found) to the computer variable.

Something like the following (haven't tried it, but should work)

replace this block of code

computer = ActiveDirectory.getComputerADRecursively(vm);

System.log("Computer count: "+computer.length);

for each (pc in computer) {

    System.log("Checking computer: "+pc.name);

    if (vm.toLowerCase() == pc.name.toLowerCase()){

        System.log("Found Computer: "+pc.name);

    }

}

with this

computer = null;

var allComputers = ActiveDirectory.getComputerADRecursively(vm);

System.log("Computer count: " + allComputers.length);

for each (pc in allComputers) {

    System.log("Checking computer: " + pc.name);

    if (vm.toLowerCase() == pc.name.toLowerCase()) {

        System.log("Found Computer: " + pc.name);

        computer = pc;

        break;

    }

}

View solution in original post

0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

ActiveDirectory.getComputerADRecursively(vm) returns an array of computers, but you are assigning it to a variable computer which is not an array but singular object. What you need is to store the array of computers into a new variable, and then lookup your target machine inside it and assign this single machine (if found) to the computer variable.

Something like the following (haven't tried it, but should work)

replace this block of code

computer = ActiveDirectory.getComputerADRecursively(vm);

System.log("Computer count: "+computer.length);

for each (pc in computer) {

    System.log("Checking computer: "+pc.name);

    if (vm.toLowerCase() == pc.name.toLowerCase()){

        System.log("Found Computer: "+pc.name);

    }

}

with this

computer = null;

var allComputers = ActiveDirectory.getComputerADRecursively(vm);

System.log("Computer count: " + allComputers.length);

for each (pc in allComputers) {

    System.log("Checking computer: " + pc.name);

    if (vm.toLowerCase() == pc.name.toLowerCase()) {

        System.log("Found Computer: " + pc.name);

        computer = pc;

        break;

    }

}

0 Kudos
BillStreet00
Enthusiast
Enthusiast
Jump to solution

Perfect thank you very much.

0 Kudos