$cs.Reg_GetExpandString
Description
Section titled “Description”Reads a REG_EXPAND_SZ registry value. Despite the name, it does not expand embedded environment variables like %ProgramFiles% in the returned value — it returns the raw stored string. Use [Environment]::ExpandEnvironmentVariables($value) if you need the expanded form. Returns an empty string if the value isn’t found.
Syntax
Section titled “Syntax”$cs.Reg_GetExpandString(string registryroot, string regkey, string regvalue)
Parameters
Section titled “Parameters”registryroot (String)
Section titled “registryroot (String)”Root hive: HKLM/HKEY_LOCAL_MACHINE, HKCU/HKEY_CURRENT_USER, or HKU/HKEY_USERS.
regkey (String)
Section titled “regkey (String)”Registry key path containing the value, relative to registryroot.
regvalue (String)
Section titled “regvalue (String)”Name of the value to retrieve. Pass "" for the key’s default value.
Return value
Section titled “Return value”String — the raw, unexpanded value. Empty string "" if the value isn’t found.
Example
Section titled “Example”$rawPath = $cs.Reg_GetExpandString("HKU", ".DEFAULT\Environment", "Path")$expandedPath = [Environment]::ExpandEnvironmentVariables($rawPath)$cs.Job_WriteLog("Expanded PATH: $expandedPath")Reading an uninstall string that contains an unexpanded %ProgramFiles% reference, then expanding it manually so it can be invoked directly.
$uninstallString = $cs.Reg_GetExpandString('HKLM', 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Contoso AppSuite', 'UninstallString')$expandedUninstallString = [Environment]::ExpandEnvironmentVariables($uninstallString)$cs.Job_WriteLog("Resolved uninstall command: $expandedUninstallString")Reading a DisplayIcon value that references %SystemRoot%, to confirm the target file actually exists on disk after expansion.
$rawIcon = $cs.Reg_GetExpandString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'DisplayIcon')$expandedIcon = [Environment]::ExpandEnvironmentVariables($rawIcon)if (-not (Test-Path $expandedIcon)){ $cs.Job_WriteLog("Warning: DisplayIcon target not found at $expandedIcon")}