You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PowerShell删除ShellIconOverlayIdentifiers时路径报错如何解决

问题原因

你筛选得到的$filteredList是RegistryKey类型的对象,当你直接将该对象作为路径参数传给Get-ItemProperty/Remove-Item时,PowerShell会默认调用对象的ToString()方法或者取Name属性做隐式类型转换,而Name属性返回的是不带PowerShell注册表提供器前缀的路径(格式为HKEY_LOCAL_MACHINE\XXX),不是可被直接识别的完整PowerShell路径。
此时系统会把这个路径视为当前工作目录下的相对路径进行拼接,最终就出现了你看到的路径重复、找不到路径的报错。


解决方法

选任意一种即可:

  • 方案1:显式传递注册表项的完整有效路径属性PSPath
    # 读取属性
    Get-ItemProperty $filteredList.PSPath
    # 测试删除
    # Remove-Item -WhatIf -Recurse $filteredList.PSPath
    
  • 方案2:通过管道传递对象,PowerShell会自动绑定PSPath属性,无需手动指定路径
    # 读取属性
    $filteredList | Get-ItemProperty
    # 测试删除
    # $filteredList | Remove-Item -WhatIf -Recurse
    
  • 方案3:手动给Name属性加上注册表提供器前缀
    # 读取属性
    Get-ItemProperty "Registry::$($filteredList.Name)"
    # 测试删除
    # Remove-Item -WhatIf -Recurse "Registry::$($filteredList.Name)"
    

修正后的完整测试脚本

Push-Location -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers

$list = Get-ChildItem -Path .
$filteredList = $list -match "DropboxExt10"
$filteredList

# 管道传递的方式最简洁
$filteredList | Get-ItemProperty
# $filteredList | Remove-Item -WhatIf -Recurse

Pop-Location

内容的提问来源于stack exchange,提问作者Gunter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 09:39:00