title: Configuring "Do not forcefully unload the users registry at user logoff" in User Profiles of Group Policy editor
body: <p>I need to write a PowerShell script that should configure the below settings of Group policy in all the machines.</p>
  
  <p><em>Gpedit.msc &rarr; Computer Configuration &rarr; Administrative Templates &rarr; System &rarr; User Profiles &rarr;  "Do not forcefully unload the users registry at user logoff"</em> to "Enabled".</p>
  
  <p>As I am aware this can be done using the registry value also</p>
  
  
  
  <pre class="lang-none prettyprint-override"><code>[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\System]
  "DisableForceUnload"=dword:00000001
  </code></pre>
  
  <p>But through the script, when I add the required registry entry, the change is not reflected in the Group Policy console. Of course, I need to use the Group Policy cmdlets!
  When I tried with <code>Set-GPRegistryValue</code> with below statement</p>
  
  <pre class="lang-psh prettyprint-override"><code>Set-GPRegistryValue -Name "User Profiles" `
    -key "HKLM\SOFTWARE\Policies\Microsoft\Windows\System\" `
    -ValueName DisableForceUnload -Type DWord -Value 1
  </code></pre>
  
  <p>It shows exception saying "A Referral was returned from the server."</p>
  
  <pre class="lang-none prettyprint-override"><code>Set-GPRegistryValue : A referral was returned from the server. (Exception from HRESULT: 0x8007202B)
  At D:\Work\XYZ\Desktop\GPO1.ps1:6 char:1
  + Set-GPRegistryValue -Name "User Profiles" -key "HKLM\SOF ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [Set-GPRegistryValue], COMException
      + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.GroupPolicy.Commands.SetGPRegistryValue 
     Command
  </code></pre>
  
  <p>What exactly I missing out here?</p>