How to Create, Link and Configure a Group Policy using Powershell

Since my post on configuring BranchCache with SCCM a few days ago, I have recently been asked if it was possible to enable the GPO settings for BranchCache using Powershell.

I thought it would be a great idea to try this out myself as I’m always up for anything Powershell related.  You’ll need at least Powershell v3 for this.

The cmdlets I used to achieve this are:

  • New-GPO
  • New-GPLink
  • Set-GPRegistryValue
  1. First of all I thought I’d create a new GPO called ‘BranchCache’ and link it to my OU called, “MyOU”
    New-GPO -Name BranchCache -Comment "Configures BranchCache" -Domain company.pri | New-GPLink -Target "ou=myOU,dc=company,dc=pri"
  2. The next thing is to enable BranchCache using powershell.  I did this by looking at the registry and seeing which values were changed each time I adjusted the GPO manually and then used the following Powershell code:
     Set-GPRegistryValue -Name "BranchCache" -Key "HKLM\SOFTWARE\Policies\Microsoft\PeerDist\Service" -ValueName "Enable" -Type DWord -Value 1
  3. If you want to disable it then use the following:
     Set-GPRegistryValue -Name "BranchCache" -Key "HKLM\SOFTWARE\Policies\Microsoft\PeerDist\Service" -ValueName "Enable" -Type DWord -Value 0
  4. If you want to set it to ‘Not Configured’ then try this:
     Set-GPRegistryValue -Name "BranchCache" -Key "HKLM\SOFTWARE\Policies\Microsoft\PeerDist\Service" -Disable

So long as you can figure out which registry value is being ‘tweaked’ via your GPO then it’s very easy to achieve the same thing using Powershell.  I’m not going to show you the other settings for BranchCache as I think you’ll agree that this is now pretty easy to figure out yourself based on the above examples.

As always, the help files in Powershell proved awesome in figuring this out.

Be the first to comment

Leave a Reply

Your email address will not be published.


*