title: Importing registry (.reg) files fails
body: <p>I'm having trouble importing .reg files on Windows Server 2012. The script works on Server 2008, works when typed at a PowerShell prompt, and works when run by "double-click" on a Server 2012 instance.</p>
  
  <p>The script unzips a file containing .reg files, then imports them into the registry.</p>
  
  <pre><code>Write-Output "Unzipping AUX Package"
  Unzip-File -File "$DOWNLOAD_DIR\$S3_AUX_PACKAGE" -Destination $destinationFolder
  Write-Output "Done unzipping AUX Package"
  
  # Import registry files in the AUX archive package
  $registryFiles = Get-ChildItem $destinationFolder | where {$_.extension -eq ".reg"}
  $registryFiles = $registryfiles | % {$_.Name}
  
  foreach ($regfile in $registryfiles) { 
          move "$destinationFolder\$regfile" "$DOWNLOAD_DIR"
          $cmd = "regedit /s `"$DOWNLOAD_DIR\$regfile`" " 
          Write-Output "$cmd"
          invoke-expression $cmd
  }
  </code></pre>
  
  <p>I can see the the correct parameters and file names appear from the Write-Output entries:</p>
  
  <pre><code>Unzipping AUX Package
  09:30:08: Done unzipping AUX Package
  09:30:09: regedit /s "c:\\downloads\ControlSet001-110-64.reg"
  09:30:11: regedit /s "c:\\downloads\CurrentControlSet110-64.reg"
  09:30:11: regedit /s "c:\\downloads\HKCU110-64.reg"
  09:30:11: regedit /s "c:\\downloads\HKLM110-64.reg"
  </code></pre>
  
  <p>But it only seems to be importing the first two .reg files - both the ControlSet files. The other two "HKCU" and "HKLM" don't import at all.</p>
  
  <p>These are the paths these REG files are trying to write to:</p>
  
  <p><strong>ControlSet001-110-64.reg</strong> - <code>HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\AdminService11.0</code></p>
  
  <p><strong>CurrentControlSet110-64.reg</strong> - <code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\AdminService11.0</code></p>
  
  <p><strong>HKCU110-64.reg</strong> - <code>HKEY_CURRENT_USER\SOFTWARE\PSC</code></p>
  
  <p><strong>HKLM110-64.reg</strong> - <code>HKEY_LOCAL_MACHINE\SOFTWARE\PSC</code></p>
  
  <p>In another script, I'm able to import REG files to write to <code>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\</code> which is weird since I'm unable to write to it's parent node <code>SOFTWARE</code>.</p>
  
  <p>I get the same result with <code>regedit /s</code> or <code>reg import</code>.</p>
  
  <p>How can I investigate this issue? Any pointers? Can I debug individual PowerShell lines - maybe verbose output? Does PowerShell have an equivalent for importing registry files? Please help!</p>