Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Remove Symbolic Link Windows

Tags:

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?

like image 680
thebusiness11 Avatar asked Aug 06 '17 21:08

thebusiness11


2 Answers

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" 
like image 91
Mathias R. Jessen Avatar answered Sep 19 '22 16:09

Mathias R. Jessen


If you want to change the target path of the existing symbolic link C:\SPI from "C:\Users\Chino\Dropbox (Reserve Membership)\" to "C:\Users\Chino\Dropbox (Reserve Membership)\SPI\" you do not need to delete the link beforehand. Simply including the -Force parameter to overwrite the link works for me in PowerShell 5.1 on Windows 10 Pro v1603:

New-Item -ItemType SymbolicLink -Path C:\SPI -Target "C:\Users\Chino\Dropbox (Reserve Membership)\SPI" -Force 
like image 33
Lance U. Matthews Avatar answered Sep 18 '22 16:09

Lance U. Matthews