Powershell 删除断开的链接

Powershell 删除断开的链接,powershell,hyperlink,Powershell,Hyperlink,我需要删除一个文件夹的所有内容,其中可能包括其他断开的链接。文件夹路径由变量提供。问题是PowerShell无法删除断开的链接 $folderPath = "C:\folder\" 尝试1: Remove-Item -Force -Recurse -Path $folderPath 失败并出现错误: Remove-Item : Could not find a part of the path 'C:\folder\brokenLink'. At line:1 char:1 + Remove

我需要删除一个文件夹的所有内容,其中可能包括其他断开的链接。文件夹路径由变量提供。问题是
PowerShell
无法删除断开的链接

$folderPath = "C:\folder\"
尝试1:

Remove-Item -Force -Recurse -Path $folderPath
失败并出现错误:

Remove-Item : Could not find a part of the path 'C:\folder\brokenLink'.
At line:1 char:1
+ Remove-Item -Force -Recurse -Path $folderPath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\folder\brokenLink:String) [Remove-Item], DirectoryNot 
   FoundException
    + FullyQualifiedErrorId : RemoveItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
尝试2:

Start-Job { cmd /c rmdir $folderPath }
失败,因为
$folderPath
按原样传递,而不是按其值传递:

Start-Job { cmd /c rmdir $folderPath } | select command

Command                                                                                             
-------                                                                                             
 cmd /c rmdir $folderPath                                                                           
除了使用
.NET
框架,还有什么建议吗

编辑
通过断开的链接,我指的是一个指向以前挂载的分区的文件夹,它已经不存在了。文件夹仍然可用,但当尝试导航到该文件夹时,会发生此错误,因为目标不再存在:
错误:

C:\folder\brokenLink指的是一个不可用的位置。信息技术 可能在这台计算机的硬盘上,或者在网络上。核对 请确保磁盘已正确插入,或者 已连接到Internet或您的网络,然后重试。如果是 仍然无法定位,该信息可能已移动到其他位置 不同的位置

这将有助于:

$folderPath = "C:\folderContaingBrokenSymlinks\";
$items = ls $folderPath -Recurse -ea 0;
foreach($item in $items){
    if($item.Attributes.ToString().contains("ReparsePoint")){
        cmd /c rmdir $item.PSPath.replace("Microsoft.PowerShell.Core\FileSystem::","");
    }
    else{
        rm -Force -Recurse $item;
    }
}

你能解释一下你所说的“断开的链接”是什么意思吗?你有一个装满快捷方式文件的文件夹吗?还是什么?@TrevorSullivan我已经用我的解释编辑了这个问题。你能解释一下吗,而不是仅仅粘贴片段?