Oct 052018
 

Remove-Item cannot be used to remove symbolic link to directory as it will remove the content of the directory it points to (so be careful!).

To safely remove a symbolic link from the file system using PowerShell, add the following function to your script:

From: PowerShell Gallery | Private, LinkUtils

function Remove-Symlink {
    <# 
    .SYNOPSIS 
        Removes a symbolic link. 
    #>
    param (
        [Parameter(Position=0, Mandatory=$true)]
        [string] $Link
    )    
    # Remove-Item cannot be used to remove symbolic link to directory as it
    # will remove the content of the directory it points to.
    [System.IO.Directory]::Delete($Link, $true)
}

Remove-Symlink -Link [path to the symbolic link you wish to remove]

Done! 🙂

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.