Microsoft – PowerShell – Resolve-Path and Interop – Coding Problem

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?
http://stackoverflow.com/questions/3038337/powershell-resolve-path-that-might-not-exist

The helpful hint was:

$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath
(“.\nonexist\foo.txt”)


The old code read:


    $objMSWordFileName = Resolve-Path $wordfilename

The new code reads:


   $objMSWordFileName =  
        $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath
           ($wordfilename);

 

 


References
:

1) PowerShell: resolve path that might not exist?
http://stackoverflow.com/questions/3038337/powershell-resolve-path-that-might-not-exist

2) The Quickest way to resolve paths
http://blog.start-automating.com/?post=The%20Quickest%20Way%20To%20Resolve%20Paths

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s