powerjobs_processor:jobprocessor:jobs:creating_job_scripts

Creating Job Scripts

To get started with creating a custom job, open the powershell IDE or editor of choice. The powerJobs Processor ISE shortcut in the start menucan also be used which already opens one of our sample jobs.

During development it can be useful to be able to start the whole script or parts of it without having to run it on the job processor.
To achieve this it a few important components of the Job Environment need to be re-created:

Import the powerJobs Module by calling Import-Module powerJobs.
This will also import powerVault as well as any modules place in the powerJobs modules dir.
Connect to Vault using the Open-VaultConnection cmdlet to have $vault, $vaultConnection and $vaultExplorerUtil available.

After connecting to the Vault successfully, a test file or any other Vault entity can be retrieved and assigned to a variable for imitating the behavior of Setup_job.ps1.
For example set the $file variable to the first .idw file that is found in Vault:

$file = Get-VaultFile -Properties @{'File Extension'='idw'} #Search for a Drawing file

Our standard delivery comes with a couple of sample jobs that can be used as templates for new jobs.
Choose one of those job scripts and place a copy of the script in the %ALLUSERSPROFILE%\coolOrange\powerJobs\Jobs directory.
Give your new Job a meaningful name in the format YourCompanyName.SomeJobName.ps1.

If you prefer to do customizations, for example some sample jobs don't allow all supported formats, the new script can be extend by adding the desired extensions like iam, ipt or ipn:

if( @("idw","dwg","iam","ipt","ipn") -notcontains $file._Extension ) {
    Write-Host "Files with extension: '$($file._Extension)' are not supported"
    return
}
An other example would be to changed the filename of the output file and prefix it with 'generated_'.
This can easily be achieved by changing the according variable in the script:
$localPDFfileLocation = "$workingDirectory\generated_$($file._Name).pdf"

Create a new script file with a meaningful name in the IDE and place it in %ALLUSERSPROFILE%\coolOrange\powerJobs\Jobs with the file extension .ps1.
In this example we are going to download the file, open it in the Inventor application and export it as PDF.

Download the file from Vault

We will use the Save-VaultFile cmdlet to download the file to our working directory.

$workingDirectory = "C:\Temp\$($file._Name)"
$downloadedFiles = Save-VaultFile -File $file.'Full Path' -DownloadDirectory $workingDirectory

Open the file in Inventor

After downloading the file to the working directory we will use the Open-Document cmdlet to open the file in Inventor.

$file = $downloadedFiles | select -First 1
Open-Document -LocalFile $file.LocalPath -Application 'Inventor'

Exporting the file

Now we can export the document as PDF, using the Export-Document cmdlet.

$localPDFfileLocation = "C:\Temp\$($file._Name).pdf"
Export-Document -Format 'PDF' -To $localPDFfileLocation

Closing the opened file

Finally we close the file and clean up the working directory, using the Close-Document and Clean-Up cmdlet.

Close-Document
Clean-Up -folder $workingDirectory

To run the job on the job processor see the Registered Jobs section and Queueing custom jobs.