Enable-GphGlobalStore.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#Requires -RunAsAdministrator
function Enable-GphGlobalStore
{
  <#
      .SYNOPSIS
      Sets the Default Policy Template Store to the Central Policy Store.
 
      .DESCRIPTION
      When the Group Policy Editor is started, it searches for a Central Policy Store by Default, which
      is located on each Domain controller inside the Sysvol-Share. This Cmdlets sets the Central Store
      as default, which might be necessary after switching the default to the Local Store with
      Enable-GphLocalStore.
 
      .EXAMPLE
      Enable-GphGlobalStore
      Sets "\\<your Domain>\Sysvol\<your Domain\Policies\PolicyDefinitions" as the Default Store for Policy Templates.
 
      .NOTES
      Author: Holger Voges
      Date: 2018-11-16
      Version: 1.0
  #>

  [cmdletbinding()]
  param()    
    
    If ( (Get-OsVersion).Versionnumber -lt 6.3)
    {
      Throw 'Switchting between Localstore and Globalstore needs at Least Windows 8.1'
    }
    
    $LocalStoreKey = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Group Policy\'
    Try 
    {
      If (-not ( test-path -Path $LocalStoreKey ))
      {
        $null = New-Item -Path $LocalStoreKey
        $Null = New-ItemProperty -Path $LocalStoreKey -Name ENABLELOCALSTOREOVERRIDE -PropertyType DWord -Value 0
      }
      Else
      {
        Set-ItemProperty -Path $LocalStoreKey -Name ENABLELOCALSTOREOVERRIDE -Value 0
      }

      Write-Verbose "$LocalStoreKey set to 0"
    }
    Catch
    {
        Write-Error $_.Exception.Message
    }
}