Microsoft – PowerShell – Resolve-Path and Interop – Coding Problem
In the last couple of days, just had so much problem trying to get Resolve-Path to work.
First it was that if the file does not exist, it barks.
Then it appears that using Resolve-Path causes a bit of problems when the resulting file
name is passed as one of the parameters to Interop Code such as Excel.
The error message we were getting read as:
"Type mismatch. (Exception from HRESULT: 0x80002005 (DISP_E_TYPEMISMATCH))"
After countless days dealing with Resolve-Path, enough Googling landed me where I needed be:
Everyone’s favorite Coding Tool, stackoverflow.com
The specific web page:
Powershell: resolve path that might not exist?
The helpful hint was:
The old code read:
$objMSWordFileName = Resolve-Path $wordfilename
The new code reads:
$objMSWordFileName = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath ($wordfilename);
1) PowerShell: resolve path that might not exist?
2) The Quickest way to resolve paths