Start a new topic

Publish PDF to External folder structure matching Vault folder structure

I am new to scripting and looking for some help with a script option to publish PDF's with PowerJobs to en external network folder matching the Vault folder structure.  It looks like the simple option would be to publish all PDF's to a single external folder location.  Over time, the single folder option will have too many files contained in a single folder.


For example in Vault if a file is processed to create a PDF in “$\ADV\Current\9103 GM Silao GA\Mech\Detail” the local workspace for that file for me would be “C:\Workspace\ADV\Current\9103 GM Silao GA\Mech\Detail”.  What is the best method to use to copy the PDF to an external network drive on publish matching the Vault folder structure?  It looks like we can get the $File.FullPath variable and will need to slice up the path for the new network folder destination. 


Destination Example: “\\server3\groups\ADV\Current\9103 GM Silao GA\Mech\Detail\NewPdfFile.pdf”

Any script examples or direction would be appreciated.

Thank you!

1 Comment

Hello Peter,

it is best to keep the PDF creation locally and then use the Copy-Item commandlet to move it to your network share right after its creation. As you have to check if the target directory exists before copying and because you probably want to create it if it doesn't it is a good function, so you don't have to rewrite the code every time you want to copy something in a job.

I lack the time right now to make a thorough tutorial, but here is some sample code. Let me know if you have any specific questions about it.


function Copy-ExportedFile {
	if( (Test-Path $CopyDirectory) -eq $false ) {
		$null = New-Item -ItemType Directory -Path ($CopyDirectory)
		if( (Test-Path $CopyDirectory) -eq $false ) {
			throw "Could not create directory $($TargetDirectory.FullName)"
	$CopyFullPath = Join-Path $CopyDirectory ( [System.IO.Path]::GetFileName($SourceFullPath) )
	$null = Copy-Item $SourceFullPath $CopyFullPath -Force
	if( (Test-Path $CopyFullPath) -eq $false ) {
		throw "Could not copy $($SourceFullPath.FullName) to $($TargetFullPath)"

$workingDirectory = "C:\TEMP\$($file._Name)"
$copyShare = "\\someserver\share"
$copyDirectory = Join-Path $copyShare $file._EntityPath.Substring(2)
$localPDFfileLocation = "$workingDirectory\$($file._Name).pdf"

#Generate PDF locally

Copy-ExportedFile $localPDFfileLocation $copyDirectory

#Clean up temporary local files



Thomas Rossmeisl

Technical Support

Please mark your thread as solved if your question was answered

Login or Signup to post a comment