Export-Document fails when -To directory doesn't exist and contains dash(-) charachter

Export-Document of Inventor drawing fails with "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"

Issue

The Export-Document cmdlet fails when the path passed to the -To parameter contains the dash character and at least one directory doesn't exist yet. It doesn't matter if the dash character is used in one of the existing folders or one of the to-be created folders.

Cause

This happens if a custom $workingDirectory is defined in the script and one of the folders doesn't exists yet and a dash(-) character is used anywhere in the path. 

Solution

If you run into this issue the easiest solution is to create your working directory in case it doesn't exist. To do this you can use the PowerShell New-Item cmdlet.

$workingDirectory = 'C:\Temp\powerJobs Processor\test-folder' 
if(-not (Test-Path -LiteralPath $workingDirectory)) {
$null = New-Item -Path $workingDirectory -ItemType Directory
}

$localPDFfileLocation = "$workingDirectory\test.pdf"
$exportResult = Export-Document -Format 'PDF' -To $localPDFfileLocation -Options "$($env:POWERJOBS_MODULESDIR)Export\PDF_2D.ini"