$cs.Reg_ExistVariable
Description
Section titled “Description”Checks whether a named value exists under a registry key. Returns $false (not an exception) if either the key or the value is missing.
Syntax
Section titled “Syntax”$cs.Reg_ExistVariable(string registryroot, string regkey, string regvariable)
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.
regvariable (String)
Section titled “regvariable (String)”Name of the value to check for.
Return value
Section titled “Return value”Boolean — $true if the value exists, otherwise $false.
Example
Section titled “Example”if ($cs.Reg_ExistVariable('HKLM', 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'Everything')){ $cs.Reg_DeleteVariable('HKLM', 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'Everything')}Checking that a specific setting exists before reading it with Reg_GetString, to distinguish “not configured” from “configured as empty string”.
if ($cs.Reg_ExistVariable('HKLM', 'SOFTWARE\Contoso\AppSuite', 'InstallPath')){ $installPath = $cs.Reg_GetString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'InstallPath') $cs.Job_WriteLog("AppSuite installed at: $installPath")}else{ $cs.Job_WriteLog("InstallPath setting not found")}Verifying a licensing value is present before proceeding with a license-dependent install step.
if (-not $cs.Reg_ExistVariable('HKLM', 'SOFTWARE\Contoso\AppSuite\Licensing', 'LicenseKey')){ Exit-PSScript -exitcode 1 -exitmessage "No license key configured, aborting install"}