Share via


Using the GPMC Class Library from Windows PowerShell

This topic lists the steps required to use the Group Policy Management Console (GPMC) functionality from a Windows PowerShell session.

  1. Install the GPMC Class Library. (See Installing the GPMC Class Library.) After you’ve ensured that the GPMC Class Library is properly installed and enabled, you can easily access the GPMC Class Library types from a Windows PowerShell session by importing the Microsoft.GroupPolicy.Management assembly.

  2. To find the version number and public key token for the Microsoft.GroupPolicy.Management assembly installed in your machine, open Windows Explorer and browse to %windir%\Assemblies\GAC_MSIL\Microsoft.GroupPolicy.Management. The folder name will indicate the assembly version and public key token. For example, a folder of 2.0.0.0__31bf3856ad364e35 indicates a version of 2.0.0.0 and a public key token value of 31bf3856ad364e35. Make a note of these two values as you will need them shortly.

  3. Start a Windows PowerShell session.

  4. Using the Assembly.Load method, load the GPMC assembly as follows:

    $assembly=[reflection.assembly]::Load("Microsoft.GroupPolicy.Management, Version=2.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35")
    

    The syntax of putting the type name - reflection.assembly - in square brackets is how static methods are called in PowerShell. As the Assembly.Load methods are all static methods, this syntax is needed for the command to run properly. Also note that you'll need to modify the Version and PublicKeyToken parameters according to what you determine in the first step of this process.

  5. At this point, you can access any public GPMC Class Library type exposed by the Microsoft.GroupPolicy.Management assembly. The following is an example of instantiating the GPDomain object by using the current domain and then printing out the name of that domain. (The type must be fully qualified with the Microsoft.GroupPolicy namespace identifier.)

    $domain = new-object Microsoft.GroupPolicy.GPDomain
    $domain.DomainName