6

I want to create a new Hardlink with the PowerShell Community Extensions PSCX commandlet New-Hardlink http://pscx.codeplex.com/. I have read the man file and tried almost every combination of commands but it won't work. What am I missing? (I know about fsutil, but I want to use this commandlet/alias)

Here is the directory structure: E:\Source E:\Test

Here are some variations of the command that I have tried:

New-Hardlink E:\Test\Source E:\Source
New-Hardlink -Path:"E:\Test\Source" -Target:"E:\Source"
New-Hardlink E:\Source E:\Test\Source
New-Hardlink E:\Source E:\Test\
New-Hardlink -P:"E:\Source" -T:"E:\Test\Source"

Here is the supposed syntax:

New-Hardlink [-Path] <String> [-Target] <String> [<CommonParameters>]

-Path <String>
    Path to the new link.

-Target <String>
    Target of the link.

The result is always some from of:

New-Hardlink : Unable to find the file 'E:\Source.

Does this command not work with directories but only with files?

3
  • 2
    Hey - can you log a bug on the pscx.codeplex.com issue tracker for this? I'll fix this in the next release - it really should be checking that the hardlinks are for files only. New-Junction is what you want (answered below). Thanks! Commented Aug 21, 2009 at 16:07
  • Thanks, here's the issue link pscx.codeplex.com/WorkItem/View.aspx?WorkItemId=24422 Commented Sep 1, 2009 at 9:46
  • Hardlinks got easier in Win10: stackoverflow.com/questions/31863258/… Commented Aug 6, 2015 at 18:33

2 Answers 2

8

I will sheepishly answer my own question.

Yes, indeed Hardlinks refer to files. To accomplish this with directories the New-Junction command should be used like so:

New-Junction E:\Test\Dest E:\Source

The first parameter refers to the location you would like to place the new Junction.

The second parameter refers to the directory you wish to Junction

Sign up to request clarification or add additional context in comments.

Comments

5

Powershell 5+ include a native way to create any types of hard-/soft-links and junctions.

For those coming from Google:

PowerShell 5.0 and above have support for creating Symbolic Links and Junctions using the New-Item cmdlet.

In the following, clicking on B.txt will take you to A.txt. Similarly for a directory.

# To create a symbolic link on a file:
New-Item -ItemType SymbolicLink -Name B.txt -Target A.txt
New-Item -ItemType SymbolicLink -Path C:\Temp\B.txt -Value A.txt

# To create a hard-link on a file:
New-Item -ItemType HardLink -Path C:\B.txt -Value C:\A.txt

# To create a symbolic link on a directory:
New-Item -ItemType SymbolicLink -Name B_Directory -Target C:\A_Directory

# To create a junction on a directory:
New-Item -ItemType Junction -Path C:\Junction -Value C:\A_Directory

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.