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
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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! 🙂