How to create PDFs with custom filenames

$customName = "customFileName" 
$vaultPDFfileLocation = "{0}/{1}.pdf" -f $file.Path, $customName
$PDFfile = Add-VaultFile -From $localPDFfileLocation -To $vaultPDFfileLocation -FileClassification DesignVisualization
  • Define a custom filename
  • Join the base path and the new filename
  • Use the joined path as the '-To' parameter when calling the 'Add-VaultFile' commandlet

Examples

Use the original filename without its extension and the revision as the custom filename:

$revision = "";
if($file.Revision -ne $null)
{
    $revision = "-" + $file.Revision
}
$vaultPDFfileLocation = "{0}/{1}.pdf" -f $file.Path, ([System.IO.Path]::GetFileNameWithoutExtension($file._name) + $revision)
  • Get the revision
  • Join the base path, the filename without extension and the revision

 

Use the part number and the current month as the custom filename:

This example uses the original filename in case there is no part number specified.

$fileName = $file._PartNumber
if($fileName -eq $null){
    $fileName = ([System.IO.Path]::GetFileNameWithoutExtension($file._name))
}
$currentMonth =  Get-Date -Format MMMM
$vaultPDFfileLocation = "{0}/{1}-{2}.pdf" -f $file.Path, $fileName, $currentMonth
  • Get the part number
  • If the part number is equal to null then use the original filename without its extension instead
  • Get the current month as a string
  • Join the base path, the part number / filename and the current month

Remarks

  • If the created PDF files should be added to the Vault it is recommended to not use a changing filename to avoid history loss.