As of Windows 10 PowerShell is finally capable of creating Junctions and links natively.
Howerver the Remove-Item function seems to be unaware of the junction and tries to remove the directory asking for confirmation and if it should recursively delete items within.
So, the question is: Is there a way to remove a junction using PowerShell native Cmdlets? (i.e. without calling cmd)
Is there a way to remove a junction using PowerShell?
Currently, at least in PowerShell v5, this is considered "fixed". What you can do is use the -Force
switch, else you will get an error calling the path an NTFS junction. The reason that I at least use the quotes on fixed is that using the switch will still make the message about children in the directory show up. Selecting Y will still only delete the junction in my testing using PSv5.
Remove-Item "C:\temp\junction" -Force -Confirm:$False
If that doesn't work for you or you don't have v5 you can use the .Net method to delete a directory. This appears to work correctly as well.
[io.directory]::Delete("C:\temp\junction")