Creating hard and soft links using PowerShell

前端 未结 11 1727
攒了一身酷
攒了一身酷 2020-12-04 05:04

Can PowerShell 1.0 create hard and soft links analogous to the Unix variety?

If this isn\'t built in, can someone point me to a site that has a ps1 script that mimi

11条回答
  •  执念已碎
    2020-12-04 05:40

    I combined two answers (@bviktor and @jocassid). It was tested on Windows 10 and Windows Server 2012.

    function New-SymLink ($link, $target)
    {
        if ($PSVersionTable.PSVersion.Major -ge 5)
        {
            New-Item -Path $link -ItemType SymbolicLink -Value $target
        }
        else
        {
            $command = "cmd /c mklink /d"
            invoke-expression "$command ""$link"" ""$target"""
        }
    }
    

提交回复
热议问题