def build_property_spec(client_factory, type='VirtualMachine',
                        properties_to_collect=None,
                        all_properties=False):
    """Builds the Property Spec.

    :param client_factory: Factory to get API input specs
    :param type: Type of the managed object reference property
    :param properties_to_collect: Properties of the managed object reference
                                  to be collected while traversal filtering
    :param all_properties: Whether all the properties of managed object
                           reference needs to be collected
    :return: Property spec
    """
    if not properties_to_collect:
        properties_to_collect = ['name']

    property_spec = client_factory.create('ns0:PropertySpec')
    property_spec.all = all_properties
    property_spec.pathSet = properties_to_collect
    property_spec.type = type
    return property_spec