# Creating Job Scripts ```{image} /img/jobprocessor/jobs/powerjobs_ise.png :align: right :width: 200px ``` ## Choose PowerShell IDE To get started with creating a custom job, open the PowerShell IDE or editor of choice. The _powerJobs Processor ISE_ shortcut in the start menu can also be used which already opens one of our [](). ## Prepare PowerShell environment 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 []() need to be re-created. Import the powerJobs Module by calling `Import-Module powerJobs`.\ This will also import []() as well as any modules placed in the [powerJobs modules directory]().\ Next a connection to Vault needs to be established using the *Open-VaultConnection* cmdlet to have the `$vault`, `$vaultConnection` and `$vaultExplorerUtil` variables 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: ```powershell $file = Get-VaultFile -Properties @{'File Extension'='idw'} #Search for a Drawing file ``` The variable `$workingDirectory` holds the path to a temporary directory (located in *C:\\Temp\\powerJobs Processor\\...*) where e.g. Vault files can be downloaded or file exports will be generated.\ All the files which are created in this directory during the development phase, will be automatically cleaned up at the next job execution.\ Alternatively, they can be removed at any time using the [Clean-Up]() cmdlet. ```powershell Clean-Up -folder $workingDirectory ``` ## Choose from Sample Jobs Our standard delivery comes with a couple of []() 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_: ```powershell 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 name of the exported target file. In this example the according filename variable is extended with the revision number of the Vault source file: ```powershell $pdfFileName = "$($file._Name)_$($file._Revision).pdf" ``` ## Start from Scratch 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 []() cmdlet to download the file to our working directory. ```powershell $downloadedFiles = Save-VaultFile -File $file.'Full Path' -DownloadDirectory $workingDirectory ``` ## Open the file in Inventor After downloading the file we will use the [open-document]() cmdlet to open the file in Inventor. ```powershell $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. ```powershell $pdfFileName = "$($file._Name).pdf" Export-Document -Format 'PDF' -To "$workingDirectory/$pdfFileName" ``` ## Closing the opened file Finally we close the file using the []() cmdlet. ```powershell Close-Document ``` To run the job on the job processor see the [Registered Jobs]() section and [Queueing custom jobs]().\ If values in the job regularly change, it is also possible to declare [settings]() in the job that can be easily modified in the [powerJobs Settings Dialog]() user interface.