$cs.Reg_GetExpandString
Description
Section titled “Description”Reads a REG_EXPAND_SZ registry value. Environment variables in the stored value, such as %ProgramFiles% or %SystemRoot%, are expanded before the value is returned. Returns an empty string if the value isn’t found.
The variables are expanded with the environment of the account that runs the PowerPack, which is SYSTEM. User-specific variables therefore point to the SYSTEM profile — for example, %USERPROFILE% becomes C:\Windows\system32\config\systemprofile. If you need the raw, unexpanded string, read it with PowerShell instead: (Get-Item 'HKLM:\SOFTWARE\Contoso\AppSuite').GetValue('DisplayIcon', $null, 'DoNotExpandEnvironmentNames').
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. 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.
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 value with environment variables expanded. Empty string "" if the value isn’t found.
Example
Section titled “Example”$defaultPath = $cs.Reg_GetExpandString("HKU", ".DEFAULT\Environment", "Path")$cs.Job_WriteLog("PATH of the default profile: $defaultPath")Reading an uninstall string that contains a %ProgramFiles% reference. The returned value already contains the full path, so it can be used directly.
$uninstallString = $cs.Reg_GetExpandString('HKLM', 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Contoso AppSuite', 'UninstallString')$cs.Job_WriteLog("Resolved uninstall command: $uninstallString")Reading a DisplayIcon value that references %SystemRoot%, to confirm the target file actually exists on disk.
$iconPath = $cs.Reg_GetExpandString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'DisplayIcon')if (-not (Test-Path $iconPath)){ $cs.Job_WriteLog("Warning: DisplayIcon target not found at $iconPath")}