我正在尝试运行 Powershell 脚本以通过注册表清除运行历史记录。它工作得很好,但我遇到的问题是我希望它显示注册表值数据,但我无法让它正确显示。这是脚本:
function Delete
{
$Reg = Get-RegistryValues 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU'
foreach ($Value in $Reg)
{
$Item = Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\' -name $Value
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes",""
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No",""
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)
$caption = "Warning!"
$message = ("Do you want to delete the run value "+$Item)
$result = $Host.UI.PromptForChoice($caption,$message,$choices,0)
if($result -eq 0)
{
Remove-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU' -name $Value
}
if($result -eq 1) { }
}
}
function Get-RegistryValues($Key)
{
(Get-Item $Key).GetValueNames()
}
Delete
每当我尝试运行它时,我都会得到 $Message 的以下输出
Do you want to delete the run value @{MRULIST=idhgfcaeb}
有谁知道获取价值数据的方法,所以它是:
idhgfcaeb
工作解决方案:
function Delete
{
$Reg = Get-RegistryValues 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU'
foreach ($Value in $Reg)
{
if ($Value -eq 'MRUList') {Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\' -name $Value -value ' '}
Else
{
$Item = (Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\' -name $Value).$Value.TrimEnd("\1")
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes",""
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No",""
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)
$caption = "Warning!"
$message = ("Do you want to delete the run value "+$Item)
$result = $Host.UI.PromptForChoice($caption,$message,$choices,0)
if($result -eq 0)
{
Remove-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU' -name $Value
}
if($result -eq 1) { }
}
}
}
function Get-RegistryValues($Key)
{
(Get-Item $Key).GetValueNames()
}
Delete