I have created a script which will search for the following registry value HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations
and if it is present, delete it.
However, I am struggling to query the single value I want to delete rather than all values within ..\Session Manager\
. I have the following code:
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(‘LocalMachine’, $computer)
$regKey = $reg.OpenSubKey(“SYSTEM\\CurrentControlSet\\Control\\Session Manager\\”,$true )
foreach ($key in $regKey.GetValueNames()) {
if ($key -eq “PendingFileRenameOperations”)
{
$regKey.DeleteValue($key)
Write-Host "PendingFileRenameOperations key deleted successfully" -ForegroundColor Green
}
else
{
Write-Host "Key does not exist. Please assign to Second Line for further investigation" -ForegroundColor Red
}
}
Which outputs the following:
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
Key does not exist. No further action required
PendingFileRenameOperations key deleted successfully
Is it possible to just output either Key does not exist. No further action required
or PendingFileRenameOperations key deleted successfully
rather than querying every single value?