Pro Tips from the Trenches: The Resolve-Path PowerShell cmdlet

You’re designing a reusable tool in PowerShell and decide a function is the most appropriate type of command to accomplish the task at hand. It will accept a FilePath parameter which will be used to specify both the path and filename to a destination file. The path should already exist, but the file may or may not already exist.

For simplicity, I’ve stripped away the complexity so the problem is more apparent. This function validates that the parent path exists and then returns the absolute path where the output file would be created once the remainder of the function is written:


It works great based on the previous results, but when specifying a UNC path, it doesn’t return a usable path:


In this scenario, the problem is immediately identifiable, but if the path itself wasn’t displayed in the previous set of results and an attempt was made to write to a file in that location, a cryptic error message would be returned.

The solution to this problem is to use the ProviderPath property of the Resolve-Path cmdlet:


Hours could be spent troubleshooting a problem such as the one demonstrated in this scenario, but the fix for this particular problem is simply choosing the specific property that not only works with local file paths, but also with UNC paths.

A bonus tip which was shown in the first example of this blog article is the Resolve-Path cmdlet can be used to generate an absolute path from a relative one. It can also be used to generate an absolute path from a relative one that contains wildcards as shown in the following example:


If you’re attending the PowerShell and DevOps Global Summit 2016, I’m presenting two sessions and if you’ve enjoyed the blog articles on this site, then you’ll definitely enjoy my presentations! I have some awesome content that I haven’t previously blogged or spoken about nor have I seen anyone else blog or speak on anything like it so I can’t wait to share the information.

Regardless if you’re attending that particular event and/or my sessions or not, if you happen to see me at a technology event, I’d love to chat with you and I’m always interested in hearing about the challenges you’re trying to solve in your environment.



  1. Jaap Brasser

    Informative article, I would name the parameter Path as that seems to be the most common parameter name used for this purpose. Perhaps you could place FilePath as a parameter alias.

    • Mike F Robbins

      When I think of Path, I literally think of the “Path” without a file name. I used FilePath for the parameter name after looking at what the native (built-in) Out-File cmdlet uses for parameter names.

      • Jaap Brasser

        I guess it comes down to personal preference, the majority of the PowerShell cmdlets uses path so I decided to standardize on that.

        echo path filepath|%{gcm -parametername $_|measure}

        There’s no right or wrong here, as even in the PowerShell core modules they bounce between File and FilePath.


Leave a Reply

%d bloggers like this: