$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 or has no subkeys, an empty result is returned rather than throwing.
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.
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 if the path doesn’t exist or has no subkeys.
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.
$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.Count -eq 0) { $cs.Job_WriteLog("No components left, removing AppSuite root key") $cs.Reg_DelTree('HKLM', 'SOFTWARE\Contoso\AppSuite')}