title: Creating Registry Keys with Powershell
body: <p>I am trying to check if a key-structure exists in the registry using powershell. If the structure does not exist, I need to create it and then I need to create the keys in the ending folder. If I run the snippets individually to create the keys, they create just fine. But running the block itself (ensuring manually within the registry that the keys don't exist) it won't create the folder structure. Not sure what the issue is. Any help would be appreciate. The code is as follows:</p>
  
  <pre><code>$Registry_Paths = "hkcu:\Software\Microsoft\Office\14.0", "hkcu:\Software\Microsoft\Office\14.0\Groove", "hkcu:\Software\Microsoft\Office\14.0\Groove\Development"
  
  foreach($Registry_Path in $Registry_Paths)
  {
  $Test_Path_Result = Test-Path -Path $Registry_Path
  if($Test_Path_Result -eq $false)
  {
      $Registry_Key_Log += "Warning: No registry key path found at " + $Registry_Path +"`n"
      $Registry_Key_Log += "Creating key now for " + $Registry_Path + "`n" + "`n"
  
      if($Registry_Path -eq "hkcu:\Software\Microsoft\Office\14.0")
      {
          try{
          New-Item -Path "HKCU:\Software\Microsoft\Office\14.0" -ItemType Key
          }
          catch
          {
              $Error_Log += "Warning: There was an error when attempting to create a new registry key, or key property for $Registry_Path"
              $Error_Log += $_.exception.message
          }
  
      }
      if($Registry_Path -eq "hcku:\Software\Microsoft\Office\14.0\Groove")
      {
          try{
          New-Item -Path "HKCU:\Software\Microsoft\Office\14.0\Groove" -ItemType Key
          }
          catch
          {
              $Error_Log += "Warning: There was an error when attempting to create a new registry key, or key property for $Registry_Path"
              $Error_Log += $_.exception.message
          }
      }
      if($Registry_Path -eq "hcku:\Software\Microsoft\Office\14.0\Groove\Development")
      {
          try{
          New-Item -Path "HKCU:\Software\Microsoft\Office\14.0\Groove\Development" -ItemType Key
          New-ItemProperty -Path "hkcu:\Software\Microsoft\Office\14.0\Groove\Development" -Value 00000001 -PropertyType dword -Name "EnableReleaseBuildDebugOutput"
          New-ItemProperty -Path "hkcu:\Software\Microsoft\Office\14.0\Groove\Development" -Value 1 -Name "TraceIdentityMessaging"
          New-ItemProperty -Path "hkcu:\Software\Microsoft\Office\14.0\Groove\Development" -Value 00000001 -PropertyType dword -Name "TraceTelespaceFetch"
          New-ItemProperty -Path "hkcu:\Software\Microsoft\Office\14.0\Groove\Development" -Value 1 -Name "TraceConnectSequence"
  
          }
          catch
          {
              $Error_Log += "Warning: There was an error when attempting to create a new registry key, or key property for $Registry_Path"
              $Error_Log += $_.exception.message
          }
      }
  
  }
  }
  </code></pre>