Powershell - Remove-ItemProperty:找不到路径,因为它不存在
Powershell - Remove-ItemProperty : Cannot find path because it does not exist
我有一个脚本可以从注册表中删除一些条目,我遇到的问题是我给 Remove-ItemProperty
cmdlet 的路径没有被识别。
这是我获取 pathSID 和定义 pathHKUClass 的地方:
#Set Variables for SID String
$objUser = New-Object System.Security.Principal.NTAccount($env:USERNAME)
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$pathSID = $strSID.Value
$pathHKUClass = "$($pathSID)_Classes"
这是我将 Remove-ItemProperty cmdlet 与路径 HKUClass 一起使用的地方:
Remove-ItemProperty -Path "HKU:$($pathHKUClass)\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" -Name "$strSW*" -WhatIf
我收到的错误信息是:
Remove-ItemProperty : Cannot find path 'HKU:\S-1-5-21-326852099-1603424837-312552118-1388315_Classes\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache' because it does not exist.
另请注意:$strSW 正在引入我在脚本其他部分使用的文件路径:
#Locating Spiceworks.exe
$Spiceworks = Get-ChildItem "C:\Users" -Recurse -Filter "Spiceworks.exe" | Select-Object -Property FullName
$strSW = @()
$strSW += $Spiceworks.FullName
如果有人知道为什么我的 $pathHKUClass 变量在这个路径下不起作用,但是 运行 提示中的那个变量输出了 HKU 下的目录,请告诉我。
这个问题是我这边的一个错误。我查看了注册表中的路径...
这是我尝试使用的路径:
"HKU:$($pathHKUClass)\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
这是我应该使用的真实路径:
"HKU:$($pathHKUClass)\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
校对我自己的代码的经验教训。
我有一个脚本可以从注册表中删除一些条目,我遇到的问题是我给 Remove-ItemProperty
cmdlet 的路径没有被识别。
这是我获取 pathSID 和定义 pathHKUClass 的地方:
#Set Variables for SID String
$objUser = New-Object System.Security.Principal.NTAccount($env:USERNAME)
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$pathSID = $strSID.Value
$pathHKUClass = "$($pathSID)_Classes"
这是我将 Remove-ItemProperty cmdlet 与路径 HKUClass 一起使用的地方:
Remove-ItemProperty -Path "HKU:$($pathHKUClass)\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" -Name "$strSW*" -WhatIf
我收到的错误信息是:
Remove-ItemProperty : Cannot find path 'HKU:\S-1-5-21-326852099-1603424837-312552118-1388315_Classes\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache' because it does not exist.
另请注意:$strSW 正在引入我在脚本其他部分使用的文件路径:
#Locating Spiceworks.exe
$Spiceworks = Get-ChildItem "C:\Users" -Recurse -Filter "Spiceworks.exe" | Select-Object -Property FullName
$strSW = @()
$strSW += $Spiceworks.FullName
如果有人知道为什么我的 $pathHKUClass 变量在这个路径下不起作用,但是 运行 提示中的那个变量输出了 HKU 下的目录,请告诉我。
这个问题是我这边的一个错误。我查看了注册表中的路径...
这是我尝试使用的路径:
"HKU:$($pathHKUClass)\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
这是我应该使用的真实路径:
"HKU:$($pathHKUClass)\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
校对我自己的代码的经验教训。