Deleting a directory symlink using PowerShell

Alasdair North - 

I'd created a directory link on Windows using mklink, and now needed to remove it in a PowerShell script. Everything I read said I should be using the Remove-Item cmdlet for this. However, I couldn't get that to work without using the -Force and -Recurse options. That caused the script to delete the whole contents of the directory I was linking to! Not what you want at all when deleting a symlink.

In the end I just ended up calling out to CMD to remove it. This worked fine.

cmd.exe /c "rmdir $symlinkPath";
← other fixes or blog
Father of three, CTO of viaLibri, and an active member of St. Barnabas Church.

Latest Posts

comments powered byDisqus