Creating hard and soft links using PowerShell

前端 未结 11 1716
攒了一身酷
攒了一身酷 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:22

    New-Symlink:

    Function New-SymLink ($link, $target)
    {
        if (test-path -pathtype container $target)
        {
            $command = "cmd /c mklink /d"
        }
        else
        {
            $command = "cmd /c mklink"
        }
    
        invoke-expression "$command $link $target"
    }
    

    Remove-Symlink:

    Function Remove-SymLink ($link)
    {
        if (test-path -pathtype container $link)
        {
            $command = "cmd /c rmdir"
        }
        else
        {
            $command = "cmd /c del"
        }
    
        invoke-expression "$command $link"
    }
    

    Usage:

    New-Symlink "c:\foo\bar" "c:\foo\baz"
    Remove-Symlink "c:\foo\bar"
    

提交回复
热议问题