This code shows you how to acquire a list of value names after specifying a key path:
param
(
[Parameter(Mandatory=$True)]
[string]$Subkey,
[Parameter(Mandatory=$True)]
[string]$Filter
)
$regkey = [Microsoft.Win32.Registry]::ClassesRoot
if($Subkey)
{
$Names = $regkey.GetSubKeyNames()
$NameList = New-Object 'System.Collections.Generic.List[string]'
foreach($n in $Names)
{
$pos = $n.IndexOf($Filter)
if ($pos -ne -1)
{
write-host $n
$NameList.Add($n)
}
}
}
else
{
$Names = $regkey.OpenSubKey($Subkey).GetSubKeyNames()
$NameList = New-Object 'System.Collections.Generic.List[string]'
foreach($n in $Names)
{
$pos = $n.IndexOf($Filter)
if ($pos -gt 0)
{
write-output $n
$NameList.Add($n)
}
}
}
No comments:
Post a Comment