VMware Aria Automation Orchestrator

 View Only
  • 1.  Wildcards in xpath with the VCPlugin methods

    Posted 8 days ago

    I wrote this code in Orchestrator to get a VC:VirtualMachine object based on a vmName string. 

    //Query format for the vCenter plugin Server. The '(?i)' makes the query case-insensitive.
    var query = "xpath:matches(name, '(?i)" + vmName + "')";
    
    //Search for all VMs based on the vmName input. 
    //Note getAllVirtualMachines() returns an array.
    var vmsFound = VcPlugin.getAllVirtualMachines(null, query);
    return vmsFound;

    This works, but it gets one and only one VM. If I input string "project1database01" it will return the corresponding type of VC:project1database01. 

    However, it doesn't match partial names. If input "project1", "project1*", or *database*", the code finds nothing. 

    I'm not sure what version of xpath Orchestrator uses, or any quirks of the getAllVirtualMachines() method. How can I get the code to find all virtual machines that contain the input string?



  • 2.  RE: Wildcards in xpath with the VCPlugin methods

    Posted 7 days ago

    Hi,

    this should work

    var namePattern = String(vmName)
      .replace(/[.+?^${}()|[\]\\]/g, "\\$&")
      .replace(/\*/g, ".*");
    
    // The vCenter finder matches the whole name, so '.*' makes this a contains search.
    var query = "xpath:matches(name, '(?i).*" + namePattern + ".*')";
    
    //Search for all VMs based on the vmName input. 
    //Note getAllVirtualMachines() returns an array.
    var vmsFound = VcPlugin.getAllVirtualMachines(null, query);
    return vmsFound;


    ------------------------------
    If you find the answer helpful, please click on the RECOMMEND button.

    Please visit my blog to get more information: https://clouddepth.com
    ------------------------------