Apply parent properties to newly created files

The generated file should have some of the properties from its parent file.

Get all the properties associated with the parent file using the Vault API and filter out the properties that you want to add to the newly created file. Add the needed properties in $propsToUpdate. In this case "Description" and "Designer" are taken from the parent file:

# Get the parent file
$propDefs = $vault.PropertyService.GetPropertyDefinitionsByEntityClassId($file.'Entity Type ID')
$propsToUpdate = @(
"Description"
"Designer"
)
foreach ($propertyName in $propDefs.DispName) {
if ($propsToUpdate -contains $propertyName) {
[hashtable]$props += @{$propertyName = $file.$propertyName}
}
}

# Export the required file
Now that you have all your needed properties in the $props variable you can export the file to the desired format using Export-Document, add the file to Vault with Add-VaultFile and then apply the properties from the parent file using:
$updatedExportedFile = Update-VaultFile -File $exportedFile._FullPath -Properties $props
 

It is also possible to take over other properties from the parent file e.g. the state:

$updatedExportedFile = Update-VaultFile -File $exportedFile._FullPath -Properties $props -Status $file.State
Keep in mind that it is only possible to do things that are also possible in Vault. For example it is not possible to change the state of a file to something that is not defined in the lifecycle definition.

Remarks