Thanks! Now I have the explicit logic.
Meanwhile, I did some experimentation (and I hate experimenting with the
registry!) and found that
Set-ItemProperty -path "HKCU:\Control Panel\Mouse" -name "SnapToDefaultButton"
will create the registry value and set its value if it does not exist.
That fits what I need right now, but it is also handy to have your conditional
logic for times when I need to know if values already exist.
> I see. I guess you could nest another if statement along the lines of:
> if ((Get-Item $RegPath).Property -notcontains $RegProp)
> New-ItemProperty -Path $RegPath -Property $RegProp -Value $RegValue
> "Larry__Weiss" wrote:
>> I think that is a lot of it, but I also need to instantiate the value if it does
>> not exist, before I set a value, don't I ?
>> PaulChavez wrote:
>>> Is this what you are looking for?
>>> $RegPath = "HKCU:\Control Panel\Mouse"
>>> $RegProp = "SnapToDefaultButton"
>>> $RegValue = 1
>>> If (Test-Path $RegPath)
>>> If ((Get-ItemProperty $RegPath).$RegProp -eq $RegValue)
>>> "Value is already set"
>>> "Set value now"
>>> "Registry path does not exist"
>>> "Larry__Weiss" wrote:
>>>> I have the line written for a script to set a value in the registry as
>>>> Set-ItemProperty -path "HKCU:\Control Panel\Mouse" -name
>>>> "SnapToDefaultButton" -value 1
>>>> What I need help with is handling the situation where that value does not
>>>> already exist. I need to have some conditional logic to create it before I set it.