I am trying to make a simple PowerShell script to access the registry, and I am doing this as follows:
Foreach ($key in Get-Childitem HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{4D36E972-E325-11CE-BFC1-08002BE10318}") {
$key.name
}
There are a bunch of keys that are just numbers (the ones I want), but then where there is a name “Properties” that I don’t have access to (I don’t need it), and this key gives me the following error executing the command Foreach:
Foreach ($key in Get-Childitem HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{4D36E972-E325-11CE-BFC1-08002BE10318}") {
$key.name
}
Get-ChildItem : Requested registry access is not allowed.
At line:3 char:31
+ Foreach ($key in Get-Childitem <<<< HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{4D36E972-E325-11CE-BFC1-08002BE10318}") {
+ CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH...318}\Properties:String) [Get-ChildItem], SecurityException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0000
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0002
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0003
(...)
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0024
How can I exclude the "Properties" key and get rid of this error?
source
share