1
我試圖運行Powershell腳本來通過註冊表清除運行歷史記錄。它工作的很好,但我遇到的問題是我希望它顯示註冊表值數據,但我無法讓它正確顯示。下面是該腳本:刪除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
每當我嘗試運行此我得到以下輸出爲$消息
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
使用$項目$值給了我一個細分版本。我想知道是否有什麼可以完成的\ 1在最後: 現在它來了:cmd \ 1 mspaint \ 1的值。 – Steve
什麼變量給你這個? –
當我有$ Item。$ Value時,它將\ 1添加到出現的所有內容的末尾。我在那裏有一個$ _。TrimEnd來照顧那個。 – Steve