Skip to content

$cs.Reg_GetExpandString

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.

$cs.Reg_GetExpandString(string registryroot, string regkey, string regvalue)

Root hive: HKLM/HKEY_LOCAL_MACHINE, HKCU/HKEY_CURRENT_USER, or HKU/HKEY_USERS.

Registry key path containing the value, relative to registryroot.

Name of the value to retrieve. Pass "" for the key’s default value.

String — the raw, unexpanded value. Empty string "" if the value isn’t found.

Terminal window
$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.

Terminal window
$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.

Terminal window
$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")
}

$cs.Reg_SetExpandString $cs.Reg_GetString