Powershell运行历史记录删除
我正在尝试运行Powershell脚本以清除注册表中的运行历史记录。它工作得很好,但我遇到的问题是,我希望它显示注册表值数据,但我无法让它正确显示。以下是脚本:Powershell运行历史记录删除,powershell,registry,Powershell,Registry,我正在尝试运行Powershell脚本以清除注册表中的运行历史记录。它工作得很好,但我遇到的问题是,我希望它显示注册表值数据,但我无法让它正确显示。以下是脚本: function Delete { $Reg = Get-RegistryValues 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU' foreach ($Value in $Reg) { $Item = Get-ItemProperty
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
您可以使用:
$Item = (Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\' -Name mrulist).MRUList
或:
使用$Item.$Value可以得到一个细分版本。我想知道是否可以对结尾处的\1做些什么:现在它出现了:cmd\1 mspaint\1作为值。是什么变量提供的?当我有$Item.$Value时,它会将\1添加到出现的所有内容的结尾。我发现有一个$u.TrimEnd来处理这个问题。我弄明白了这一部分,我添加了一个额外的行来设置变量
$Value.TrimEnd(“\1”)
到'$Item=(获取ItemProperty'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\'-Name$Value)
("Do you want to delete the run value " + $Item.MRUList)