$cs.Reg_EnumKey
Description
Section titled “Description”Returns the names of the subkeys found directly under a registry key. If the path doesn’t exist, $false is returned rather than throwing. Check the key with $cs.Reg_ExistKey first, so you don’t loop over $false by mistake.
Syntax
Section titled “Syntax”$cs.Reg_EnumKey(string regroot, string regpath, bool mustexist)
Parameters
Section titled “Parameters”regroot (String)
Section titled “regroot (String)”Root hive: HKLM/HKEY_LOCAL_MACHINE, HKCU/HKEY_CURRENT_USER, or HKU/HKEY_USERS. PowerPacks run as SYSTEM, so HKCU is the SYSTEM account’s hive, not the logged-on user’s. To change user settings, see Invoke-RunAsLoggedOnUser.
regpath (String)
Section titled “regpath (String)”Registry key path to enumerate, relative to regroot.
mustexist (Boolean)
Section titled “mustexist (Boolean)”Accepted for signature compatibility but currently has no effect on behavior — the function does not throw or change behavior based on this value.
Return value
Section titled “Return value”Array of subkey names (string[]). Empty array if the key exists but has no subkeys. $false if the key doesn’t exist or can’t be opened. Empty string "" if regroot isn’t HKLM, HKCU or HKU.
Example
Section titled “Example”$regkeys = $cs.Reg_EnumKey('HKLM', 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', $true)foreach ($item in $regkeys) { $cs.Job_WriteLog("Regkey found: $item")}Enumerating installed version subkeys under a vendor key during Uninstall, so old versions can be identified and removed one by one.
if ($cs.Reg_ExistKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Versions')) { $versions = $cs.Reg_EnumKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Versions', $true) foreach ($version in $versions) { if ($version -ne '5.2.0') { $cs.Job_WriteLog("Removing outdated version key: $version") $cs.Reg_DelTree('HKLM', "SOFTWARE\Contoso\AppSuite\Versions\$version") } }}Checking how many components are registered under a key before deciding whether the whole feature tree should be torn down.
$components = $cs.Reg_EnumKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Components', $true)if ($components -is [array] -and $components.Count -eq 0) { $cs.Job_WriteLog("No components left, removing AppSuite root key") $cs.Reg_DelTree('HKLM', 'SOFTWARE\Contoso\AppSuite')}