$cs.Reg_GetString
Description
Section titled “Description”Reads a REG_SZ (string) registry value. Returns an empty string "" if the value isn’t found — never $null.
Syntax
Section titled “Syntax”$cs.Reg_GetString(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. Empty string "" if the value isn’t found.
Example
Section titled “Example”$filepath = $cs.Reg_GetString("HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe", "")if ($filepath -ne ""){ $cs.Job_WriteLog("Found 7-Zip at: $filepath")}Reading the DisplayVersion from an application’s Uninstall key to check whether the installed version is current.
$displayVersion = $cs.Reg_GetString('HKLM', 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Contoso AppSuite', 'DisplayVersion')$cs.Job_WriteLog("Currently installed version: $displayVersion")if ($displayVersion -eq '4.8.1'){ $cs.Job_WriteLog("Latest version is already installed")}Reading a value that returns "" when not configured, and falling back to a sensible default instead of leaving it blank.
$logLevel = $cs.Reg_GetString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'LogLevel')if ($logLevel -eq ''){ $logLevel = 'Info'}$cs.Job_WriteLog("Using log level: $logLevel")Related functions
Section titled “Related functions”$cs.Reg_SetString $cs.Reg_ExistVariable $cs.Reg_DeleteVariable