How to normalize and compare paths in Powershell
04:17 08 Apr 2022

I need to test two strings, which contain paths, for wether they point to the same directory or not.
Simply using a string comparison fails when comparing C:\Windows with C:\Windows\ for example.

This problem can be solved by using Join-Path as per this StackOverflow-Question, but it still leaves out other things:
For example \\server\share can sometimes be represented as UNC\server\share or \\\share

Is there a proper way to check this without using a workaround?

EDIT: I have implemented the code found in my answer in my powershell module PSHelperTools which can be downloaded using Install-Module PSHelperTools

powershell path