PowerShell 1.0可以创建类似Unix的硬链接和软链接吗?

如果这不是内置的,有人能告诉我一个网站,有一个ps1脚本模仿这个吗?

恕我直言,这是任何优秀shell的必要功能。:)


当前回答

在Windows 7下,命令为

fsutil hardlink create new-file existing-file

PowerShell发现它没有完整的路径(c:\Windows\system32)或扩展名(.exe)。

其他回答

你可以使用这个实用程序:

c:\Windows\system32\fsutil.exe create hardlink

添加“pscx”模块

不,它不是内置在PowerShell中。在Windows Vista/Windows 7上不能单独调用mklink实用程序,因为它是作为“内部命令”直接构建在cmd.exe中。

您可以使用PowerShell社区扩展(免费)。对于不同类型的重解析点,有几个cmdlet:

New-HardLink, New-SymLink, New-Junction, Remove-ReparsePoint 和其他人。

我写了一个PowerShell模块,它有MKLINK的本机包装器。https://gist.github.com/2891103

包括以下函数:

New-Symlink New-HardLink New-Junction

捕获MKLINK输出并在必要时抛出适当的PowerShell错误。

在Windows 7下,命令为

fsutil hardlink create new-file existing-file

PowerShell发现它没有完整的路径(c:\Windows\system32)或扩展名(.exe)。

Windows 10(以及Powershell 5.0)允许您通过New-Item cmdlet创建符号链接。

用法:

New-Item -Path C:\LinkDir -ItemType SymbolicLink -Value F:\RealDir

或者在你的个人资料中:

function make-link ($target, $link) {
    New-Item -Path $link -ItemType SymbolicLink -Value $target
}

打开开发人员模式,在新建项目链接时不需要管理员权限: