Powershell Remove Symbolic Link Windows

thebusiness11 picture thebusiness11 · Aug 6, 2017 · Viewed 13k times · Source

I am having issues when removing SymbolicLinks which I have created with New-Item:

New-Item -ItemType SymbolicLink -Path C:\SPI -Target "C:\Users\Chino\Dropbox (Reserve Membership)\"

I need to modify the link because it has the wrong -Target, which should be:

New-Item -ItemType SymbolicLink -Path C:\SPI -Target "C:\Users\Chino\Dropbox (Reserve Membership)\SPI"

How to remove that link and assign a new one? Alternatively, how to update the target path of the existing link?

Answer

Mathias R. Jessen picture Mathias R. Jessen · Aug 7, 2017

Calling Delete() on the corresponding DirectoryInfo object should do the trick:

(Get-Item C:\SPI).Delete()
New-Item -ItemType SymbolicLink -Path C:\SPI -Target "C:\Users\Chino\Dropbox (Reserve Membership)\SPI"