/build/static/layout/Breadcrumb_cap_w.png

Remove-ItemProperty problem (Double absurd cancellation of a registry entry)

HI

I wrote this script:


param($RemovedSID,$RemAccNameDel)

function KeyAndItemDeleted ($StartKey)
{
if ($StartKey -eq 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\PurgeAtNextLogoff') {

Remove-ItemProperty -LiteralPath $StartKey -Name $RemovedSID -WhatIf
}
else {
Remove-Item $StartKey'\'$RemovedSID -WhatIf
}

}

if (('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\PurgeAtNextLogoff.'+$RemovedSID)) {
KeyAndItemDeleted -StartKey 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\PurgeAtNextLogoff'
}


I run it thus:



powershell -ExecutionPolicy Unrestricted -file "D:\Users\xxx\Documents\b.ps1" "S-1-5-21-152799110-1058532297-3105840818-1000" "AccountNameDeleted"


but I get:


WhatIf: Performing operation "Remove Property" on target "Element: HKEY_LOCAL_M
ACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\Purge
AtNextLogoff Property: S-1-5-21-152799110-1058532297-3105840818-1000".
Remove-ItemProperty : Property S-1-5-21-152799110-1058532297-3105840818-1000 do
es not exist in the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Current
Version\NetCache\PurgeAtNextLogoff.
In D:\Users\xxx\Documents\b.ps1:7 car:31
+ Remove-ItemProperty <<<< -LiteralPath $StartKey -Name $RemovedSID
-WhatIf
+ CategoryInfo : InvalidArgument: (S-1-5-21-152799...3105840818-1
000:String) [Remove-ItemProperty], PSArgumentException
+ FullyQualifiedErrorId : System.Management.Automation.PSArgumentException
,Microsoft.PowerShell.Commands.RemoveItemPropertyCommand


Why?

THANKS

BYE

0 Comments   [ + ] Show comments

Answers (1)

Posted by: anonymous_9363 13 years ago
Red Belt
0
Ummmmmmmmmmm...maybe because
Property
S-1-5-21-152799110-1058532297-3105840818-1000
does not exist in the path
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\PurgeAtNextLogoff
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ