Skip to main content

Test-RegistryValue

SYNOPSISโ€‹

Test if a registry value exists.

SYNTAXโ€‹

Test-RegistryValue [-Key] <Object> [-Value] <Object> [[-SID] <String>] [<CommonParameters>]

DESCRIPTIONโ€‹

Checks a registry key path to see if it has a value with a given name. Can correctly handle cases where a value simply has an empty or null value.

EXAMPLESโ€‹

EXAMPLE 1โ€‹

Test-RegistryValue -Key 'HKLM:SYSTEM\CurrentControlSet\Control\Session Manager' -Value 'PendingFileRenameOperations'

PARAMETERSโ€‹

-Keyโ€‹

Path of the registry key.

Type: Object
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False

-Valueโ€‹

Specify the registry key value to check the existence of.

Type: Object
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-SIDโ€‹

The security identifier (SID) for a user. Specifying this parameter will convert a HKEY_CURRENT_USER registry key to the HKEY_USERS$SID format.

Specify this parameter from the Invoke-HKCURegistrySettingsForAllUsers function to read/edit HKCU registry settings for all users on the system.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParametersโ€‹

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTSโ€‹

System.Stringโ€‹

Accepts a string value for the registry key path.โ€‹

OUTPUTSโ€‹

System.Stringโ€‹

Returns $true if the registry value exists, $false if it does not.โ€‹

NOTESโ€‹

To test if registry key exists, use Test-Path function like so:

Test-Path -Path $Key -PathType 'Container'

https://psappdeploytoolkit.com