In PowerShell, I need resolve the target path of a junction (symlink).
for example, say I have a junction c:\someJunction
whose target is c:\temp\target
I tried variations of $junc = Get-Item c:\someJunction
, but was only able to get c:\someJunction
How do I find the target path of the junction, in this example c:\temp\target
, of a given junction?
You can get the path by doing the following:
Edit for finding the path and not the contents of the folder
We end up using this function
What's New in Windows PowerShell v5
I've checked the symlink support on the my Windows 7 machine, it's works fine.
Get target of the symbolic link as easy as to create it.
This does the trick with less work, and works even for junctions on a remote server:
If you want just the target name:
so
Also, the code below is a slight modification of the code that Josh provided above. It can be put in a file that is read multiple times, and it handles the leading
\\?\
correctly in the case of a network drive:and given the function
Get_UNCPath
above, we can improve the functionGet_JunctionTarget
as follows: