Issue

A Vault file should be downloaded with a rule set that is not possible in Save-VaultFile


Solution

function Get-VdfFile{
    Param(
        [Parameter(Mandatory=$True)]
        $File
    )
    if($File -is [Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.FileIteration]) {
        $fileMasterId = $file.EntityMasterId
    } else { $fileMasterid = $file.MasterId }
    
    $vdfFile = $vault.DocumentService.GetLatestFileByMasterId($fileMasterid)
    $vdfFile = New-Object Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.FileIteration($vaultConnection, $vdfFile)
    return $vdfFile
}


function Download-VaultFile{
<#
.SYNOPSIS
Downloads a file from Vault

.DESCRIPTION
Returns a Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.FileIteration of the downloaded file or $null. The object also has a LocalPath parameter added. 
This function was tested with Powershell 5 and is made for Vault 2018.
.PARAMETER File
A powerVault file object or VDF FileIteration object

.PARAMETER DateBiased
Currently, DateBiased only applies for when VersionGatheringOption is Revision When set to true, this will turn off ReleaseBiased, since only either DateBiased or ReleaseBiased gathering can be done.

.PARAMETER ReleaseBiased
When set to true, this will turn off DateBiased, since only either DateBiased or ReleaseBiased gathering can be done. ReleaseBiased only applies for when VersionGatheringOption is Latest or Revision

.PARAMETER VersionGatheringOption
Actual= Gathers the actual version for the relationship Latest= Gathers the latest version Revision= Gathers the appropriate version that represents the revision for the relationship

.EXAMPLE
$files = Download-VaultFile -file $file -downloadPath C:\temp\dltest -includeChildren -recurseChildren -VersionGatheringOption:Actual

.EXAMPLE
$files = Download-VaultFile -file $file -downloadPath C:\temp\dltest -includeChildren -recurseChildren -VersionGatheringOption:Latest
#>
Param(
    [Parameter(Mandatory=$true, Position=0)]
    [PSCustomObject]$File,
    [Parameter(Mandatory=$true, Position=1)]
    [String]$DownloadPath,
  [Autodesk.DataManagement.Client.Framework.Vault.Currency.VersionGatheringOption]
    $VersionGatheringOption,
    [Parameter(Mandatory=$false)]
    [Switch]$IncludeChildren,
    [Parameter(Mandatory=$false)]
    [Switch]$RecurseChildren,
    [Parameter(Mandatory=$false)]
    [Switch]$IncludeAttachments,
    [Parameter(Mandatory=$false)]
    [Switch]$DateBiased,
    [Parameter(Mandatory=$false)]
    [Switch]$ReleaseBiased
)
  try{
    $file = Get-VdfFile -file $file

    $settings = New-Object Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings($vaultconnection, $false)
    $settings.DefaultAcquisitionOption = [Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings+AcquisitionOption]::Download
    $settings.AddEntityToAcquire($file)
    $settings.LocalPath = $downloadPath
    $settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren = $IncludeChildren
    $settings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren = $RecurseChildren
    $settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeAttachments = $IncludeAttachments
    $settings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = $VersionGatheringOption
    $settings.OptionsRelationshipGathering.FileRelationshipSettings.DateBiased = $DateBiased
    $settings.OptionsRelationshipGathering.FileRelationshipSettings.ReleaseBiased = $ReleaseBiased
    $files = $vaultConnection.FileManager.AcquireFiles($settings)
        
        $fileAcquisitionResult = $files.FileResults[0] | ? { $_.File.EntityName -eq $file.EntityName}

        if($fileAcquisitionResult.Status -eq [Autodesk.DataManagement.Client.Framework.Vault.Results.FileAcquisitionResult+AcquisitionStatus]::Success ){ 
            Add-Member -InputObject $fileAcquisitionResult.File -MemberType NoteProperty -Name LocalPath -Value $fileAcquisitionResult.LocalPath.FullPath
            return $fileAcquisitionResult.File
        }
        else { return $null }
    }
    catch{
        throw("Failed to aquire files. $($Error[0])")
    }
}


Remarks

The commandlet expects a $vault and a $vaultconnection object. Those are generated by all our products and by Autodesk Vault Data Standard.