Not able to test, but hopefully this points you in the right direction: $key = "HKLM\System\Test" $Name = (Get-ItemProperty -Path $key -Name hai).hai $Valuename = "hai" $Value = "8"
If (Test-Path $key) { Write-Host "Registry Path $key exists" If (!($Name) { New-ItemProperty -path $key -name $Name -Value $value -PropertyType DWORD -Force | Out-null Write-Host "Registry Value for $key\$Name created and updated to $Value" } Elseif ($Name) { If ($Name -ne "8") { New-ItemProperty -path $key -name $Name -Value $value -PropertyType DWORD -Force | Out-null Write-Host "Registry Value for $key\$Name updated to $Value" } Elseif ($Name -eq "8") { Write-Host "Registry value for $key\$name already set to $Value" } } } Elseif (!(Test-Path $key) { New-Item -Path $key -Force | Out-Null Write-Host "Registry path $key created successfully" New-ItemProperty -path $key -name $ValueName -Value $Value -PropertyType DWORD -Force | Out-null Write-Host "Registry value $key\$ValueName created successfully and set to $Value" } On Wed, Sep 7, 2016 at 6:53 AM, Kevin Ray <kevinalive...@gmail.com> wrote: > Hi All, > > Im looking for path in registry " hklm\system\test" > > Then if test exist, then -name = hai > > If name exist then value should be 8...if value is other than 8 it should > set to 8 and if the name "hai"...not exist also it should created " hai" > with value 8......any help > >