System.GroupPolicy API Reference

The System.GroupPolicy namespace provides classes that enable developers to interact with Windows Group Policy objects, read and write policy settings, and manage Resultant Set of Policy (RSoP) data.

Contents

Overview

The System.GroupPolicy namespace contains types that represent Group Policy objects (GPOs), security filtering, WMI filters, and more. It is primarily used by system administrators and developers creating custom management tools.

Classes

Key Methods

ClassMethodDescription
GroupPolicyObjectLoad(string gpoName)Loads a GPO by its display name.
GroupPolicyObjectGetSetting(string key)Retrieves a specific policy setting.
GroupPolicyObjectCollectionGetAll()Returns all GPOs applied to the current computer.
ResultantSetOfPolicyQuery(string targetComputer)Runs an RSoP query against a target machine.

Code Examples

C# – List All GPOs on a Computer
// Requires reference to System.GroupPolicy.dll
using System;
using System.GroupPolicy;

class Program
{
    static void Main()
    {
        var gpoCollection = new GroupPolicyObjectCollection();
        foreach (var gpo in gpoCollection.GetAll())
        {
            Console.WriteLine($"Name: {gpo.Name}, Id: {gpo.Id}");
        }
    }
}
            
PowerShell – Retrieve a Specific Policy Setting
Import-Module GroupPolicy

$gpo = Get-GPO -Name "Default Domain Policy"
$setting = $gpo | Get-GPRegistryValue -Key "HKLM\Software\Policies\Microsoft\Windows\System" -ValueName "EnableLUA"
Write-Output "EnableLUA = $($setting.Value)"
            

Remarks

The System.GroupPolicy namespace is available starting with .NET Framework 4.6 and .NET 5+. It requires the client machine to run Windows 10/Server 2016 or later and to have the Group Policy Management Console (GPMC) installed.

For remote queries, ensure that the account executing the code has sufficient permissions (Domain Administrator or delegated GPO read rights).