Reputation: 229
I'm trying to run a Powershell script to clear the Run History through the registry. It works great, but the problem I'm having is that I want it to display the Registry Value Data but I can't get it to display properly. Here is the script:
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
Whenever I try to run this I get the following output for the $Message
Do you want to delete the run value @{MRULIST=idhgfcaeb}
Does anyone know of a way to get JUST the Value Data, so it would be:
idhgfcaeb
Working solution:
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
Upvotes: 1
Views: 2368
Reputation: 52619
You could use:
$Item = (Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\' -Name mrulist).MRUList
Or:
("Do you want to delete the run value " + $Item.MRUList)
Upvotes: 3