title: Test if registry value exists
body: <p>In my powershell script I'm creating one registry entry for each element I run script on and I would like to store some additional info about each element in registry (if you specify optional parameters once then by default use those params in the future).</p>
  
  <p>The problem I've encountered is that I need to perform Test-RegistryValue (like <a href="http://powershell.com/cs/blogs/tips/archive/2010/04/08/test-whether-registry-value-exists.aspx" rel="noreferrer">here</a>--see comment) but it doesn't seem to do the trick (it returns false even if entry exists).
  I tried to "build on top of it" and only thing I came up is this:</p>
  
  <pre><code>Function Test-RegistryValue($regkey, $name) 
  {
      try
      {
          $exists = Get-ItemProperty $regkey $name -ErrorAction SilentlyContinue
          Write-Host "Test-RegistryValue: $exists"
          if (($exists -eq $null) -or ($exists.Length -eq 0))
          {
              return $false
          }
          else
          {
              return $true
          }
      }
      catch
      {
          return $false
      }
  }
  </code></pre>
  
  <p>That unfortunately also doesn't do what I need as it seems it always selects some (first?) value from the registry key.</p>
  
  <p>Anyone has idea how to do this?
  It just seems too much to write managed code for this...</p>