Problems like this still exist in 2024, and this was the closet post I found to my failing search seeking a way to help me resolve a path with any number of unknown symbolic links. So, I offer my hack leveraging (Get-Item ).Target, working through the syntactic pain, in case it is a helpful starting point for someone else. Note: I only tested with "mklink /d" symbolic folders in the path.
PowerShell command lines to demo resolving input $Path in place ($Path is “resolved” as $Path, $DIR and $DIRs is stolen for scratch space):
$Path,$DIRs=(Resolve-Path $Path).Path.Split("\");
while($null -ne $DIRs){ $DIR,$DIRs=$DIRs; $Path=$Path+"\"+$DIR; $DIR=(Get-Item $Path).Target; if ($DIR.GetType().Name -eq "String[]"){$Path=$DIR[0]}; };
Batch command to use this gets more complex, having to escape some text and demoes here with input/output as %CDResolvePath% since %Path% is reserved in batch context:
for /f "delims=" %%a in (
'powershell -command "$Path,$DIRs=(Resolve-Path '"%CDPathResolved:)=^^^)%'").Path.Split('"\'");
while($null -ne $DIRs){ $DIR,$DIRs=$DIRs; $Path=$Path+'"\'"+$DIR; $DIR=(Get-Item $Path).Target; if ($DIR.GetType().Name -eq '"String[]'"){$Path=$DIR[0]}; } $Path;"'
) do set "CDPathResolved=%%a"
Batch notes: the “for loop” just gets back the output returned by the “ $Path;” at the end of the PowerShell which is “write-output”. Injection of single quotes are to escape the double quotes and pass them through to Powershell. The batch “String Replace” syntax “:)=^^^)” on the input CDPathResolved is needed to escape and pass Powershell any “)” in a pathname as “^)” since “Program Files (x86)” in file paths broke things.
Use case: I'd a build failing when I was forced to move my Jenkins build project with "mklink /d" to another drive. I worked around by setting my Current Working Path to resolved before kicking off "node.exe", though I later diagnosed that Angular’s "ng https://angular.dev/cli/build" has a handicap addressed by "preserve-symlinks" (or is it “node.exe” that is challenged? I’m not well enough educated on these matter to distinguish, and I don’t care anymore to learn more). So one could contemplate my case to see how my hack applies, but then perhaps even find out about the node/angular switches or some other context may with similar options that might more cleanly work around your case before going down the rabbit hole like me.