Powershell – How to enable a local group policy setting with PowerShell and/or an API

automationgroup-policypowershell

I just discovered I have to enable a local group policy setting (Computer Configuration -> Administrative Templates -> System -> UserProfiles) on a server running a specific application. I have a PowerShell installation script I use to install the application and configure the server. I'd like to be able to enable this group policy in my installation script. Is there a way to do this in PowerShell? If not, any other technology? I'm comfortable using the Win32 API, if that is my only option.

Best Answer

Most group policy settings are just registry keys under HKLM\Software\Policies. If your PowerShell script runs as Adminstrator, you can just set the corresponding registry value and achieve the same effect without touching Group Policy.

The mappings between registry values and GPO settings is documented by Microsoft. https://www.microsoft.com/en-us/download/details.aspx?id=25250