code: def CreateTasksFilter(pc, tasks):
      
      if not tasks:
          return None
  
      # First create the object specification as the task object.
      objspecs = [vmodl.query.PropertyCollector.ObjectSpec(obj=task)
                  for task in tasks]
  
      # Next, create the property specification as the state.
      propspec = vmodl.query.PropertyCollector.PropertySpec(
          type=vim.Task, pathSet=[], all=True)
  
      # Create a filter spec with the specified object and property spec.
      filterspec = vmodl.query.PropertyCollector.FilterSpec()
      filterspec.objectSet = objspecs
      filterspec.propSet = [propspec]
  
      # Create the filter
      return pc.CreateFilter(filterspec, True)
docs: Create property collector filter for tasks