Skip to content

$cs.Reg_DeleteVariable

Deletes a single named value from a registry key, leaving the key itself in place. Pass an empty string "" as regvalue to delete the key’s unnamed default value.

If the key or the value doesn’t exist, nothing happens. If the value can’t be deleted, for example because access is denied, the failure is written to the log and the function doesn’t raise an error.

$cs.Reg_DeleteVariable(string regroot, string regpath, string regvalue)

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.

Registry key path containing the value, relative to regroot.

Name of the value to delete. Pass "" to delete the key’s default (unnamed) value.

None.

Terminal window
if ($cs.Reg_ExistVariable('HKLM', 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'Everything'))
{
$cs.Reg_DeleteVariable('HKLM', 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'Everything')
}

Removing a single stale setting value during PostInstall cleanup, without touching the rest of the key.

Terminal window
$cs.Reg_DeleteVariable('HKLM', 'SOFTWARE\Contoso\AppSuite', 'LegacyLicenseServer')
$cs.Job_WriteLog("Removed obsolete LegacyLicenseServer setting")

Deleting a key’s default (unnamed) value by passing "" as regvalue, leaving all other named values in place.

Terminal window
$cs.Reg_DeleteVariable('HKLM', 'SOFTWARE\Classes\.contoso', '')

$cs.Reg_ExistVariable $cs.Reg_GetString $cs.Reg_DelTree