3

I am trying to create a symlink to a file on Windows using PowerShell. I am using the New-Symlink cmdlet from the PowerShell Community Extensions.

After struggling to figure out the syntax of New-Symlink I was able to get it to work correctly on my local drive. However, I am trying to get it to work on a file share and when I run the command there, I get this output

[PC-KHARPER] <~>$ New-Symlink '\\nyprodfs01\profiles$\kharper\testDir\testFile2' '\\nyprodfs01\profiles$\kharper\testFile'
New-Symlink : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:1 char:1
+ New-Symlink '\\nyprodfs01\profiles$\kharper\testDir\testFile2' '\\nyprodfs01\pro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Microsoft.Power...stDir\testFile2:UnresolvedPscxPathImpl) [New-Symlink], Unauthoriz
   edAccessException
    + FullyQualifiedErrorId : CreateSymbolicLinkError,Pscx.Commands.IO.Ntfs.NewSymlinkCommand

Is this expected output for UNC paths? Or should it be working and I'm just doing something wrong?

Kris Harper
  • 5,672
  • 8
  • 51
  • 96
  • I'm not sure if it supports the target being another UNC path, but making a symlink on windows requires elevated permissions. * Is your script running elevated? * Does the elevated user have admin privileges on the target path? – Eris Oct 17 '13 at 18:12
  • I am running an elevated prompt, but I don't have admin privileges on the fileserver. – Kris Harper Oct 17 '13 at 19:46
  • Tried with someone who has admin rights on the box, but it still doesn't work. No error message, but no success either. – Kris Harper Oct 17 '13 at 20:53
  • I do have the exact same error when doing something like `New-Symlink C:\path\to\link \\path\to\target\directory` while `mklink /D C:\path\to\link \\path\to\target\directory` works as expected. – Felix Bayer Aug 19 '14 at 07:46

1 Answers1

2

If you use the symlink support that comes with PS5 (which came out well after this question was posted) then you can mount a symlink to a UNC share.

[host]: PS> New-Item -ItemType SymbolicLink -Path <localpath> -Value \\<uncpath>

There is a problem if you need to pass credentials as New-Item doesn't take creds. The workaround I use is to mount a PSDrive to the folder and then symlink the PSDrive.

[host]: PS> New-PSDrive Z FileSystem \\<uncpath> -Credential <cred> [host]: PS> New-Item -ItemType SymbolicLink -Path <path> -Value Z:\

Ritch Melton
  • 11,498
  • 4
  • 41
  • 54