0

When i attempt to create a new symbolink link with the target (Value) path set to a string of "%UserProfile%\dir1\dir2\file.ext" the resultant path is prepended with the directory the script is run from.

$targetpath = '%UserProfile%\dir1\dir2\filename.ext'
New-Item -Path $currpath -ItemType SymbolicLink -Value ($targetpath) -Force

so if i run the script from c:\scripts\ the Value becomes c:\scripts%UserProfile%\dir1\dir2\filename.ext. Anyone know of a way around this? I am able to modify i an existing symbolic link to use this path and it functions as intended but can't seem to do this programmatically.

Note: MkLink and comobject.createshortcut exhibit the same behavior.

Mlesko
  • 21
  • 2
  • That doesn't resolve my issue though. i don't want the variable to resolve when the targetpath is passed to the new-item call. i want the path to include the literal text "%userprofile%\dir1\dir2\file.ext" – Mlesko Mar 01 '22 at 17:13
  • Please don't ask the same question multiple times. As stated in [my answer to your previous question](https://stackoverflow.com/a/71301368/45375), _symbolic links_ only support literal paths. They are distinct from _shortcut files_, and only they support `cmd.exe`-style variable references, also via the COM `.CreateShortcut()` API, but you won't see that if you _get_ property values - see my updated answer. – mklement0 Mar 01 '22 at 19:27

0 Answers0