Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4075366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:17:20+00:00 2026-05-20T17:17:20+00:00

How do I set group policies in AD? I’m able to create my OU

  • 0

How do I set group policies in AD? I’m able to create my OU but i also need to attach group policy linking to it. So this is what i have so far.

 string strOU = "OU=test454545,OU=Clients,OU=Clients,DC=domain,DC=net";
        GPMGMTLib.GPM gpm = new GPMGMTLib.GPM();
        GPMGMTLib.GPMConstants gpc = gpm.GetConstants();
        GPMGMTLib.GPMDomain gpd = gpm.GetDomain(Environment.GetEnvironmentVariable("USERDNSDOMAIN"), "", gpc.UseAnyDC);  
        GPMGMTLib.GPMSOM gpSom = gpd.GetSOM(strOU);

        GPMGMTLib.GPMGPO gpo = gpd.CreateGPO();
        gpo.DisplayName  = "TestOutCome";
        gpSom.CreateGPOLink(-1,gpo);

This still doesn’t create the GPO link, but all i want to do is link an existing GPO, anyt thoughts? And thanks for the help.

Okay getting closer, this just created a policy doesn’t actually link an existing one…

 string strGPO = "Default Security with web access";
        string strOU = "OU=test454545,OU=Clients,OU=Clients,DC=domain,DC=net";
        GPMGMTLib.GPM gpm = new GPMGMTLib.GPM();
        GPMGMTLib.GPMConstants gpc = gpm.GetConstants();
        GPMGMTLib.GPMDomain gpd = gpm.GetDomain(Environment.GetEnvironmentVariable("USERDNSDOMAIN"), "", gpc.UseAnyDC);
        GPMGMTLib.GPMSearchCriteria searchOBJ = gpm.CreateSearchCriteria();
        searchOBJ.Add(gpc.SearchPropertyGPODisplayName, gpc.SearchOpEquals, strGPO);
        GPMGMTLib.GPMGPOCollection objGPOlist = gpd.SearchGPOs(searchOBJ);
        GPMGMTLib.GPMSOM gpSom = gpd.GetSOM(strOU);
        GPMGMTLib.GPMGPO gpo = gpd.CreateGPO();
        gpSom.CreateGPOLink(-1,gpo);

Update and WORKING:

This is for linking existing GPO’s to OU’s using C#
1) install http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=0a6d4c24-8cbd-4b35-9272-dd3cbfc81887
2) Reference gpmgmt.dll (found in the install directory)
3) You might have to install .Net 1.1
4) Add References to VS
5) add using GPMGMTLib; using GPOADMINLib; to project

            string strGPO = "Default Security with web access";
        string strOU = "OU=test454545,OU=Clients,OU=clients,DC=domainh,DC=net";
        GPMGMTLib.GPM gpm = new GPMGMTLib.GPM();
        GPMGMTLib.GPMConstants gpc = gpm.GetConstants();
        GPMGMTLib.GPMDomain gpd = gpm.GetDomain(Environment.GetEnvironmentVariable("USERDNSDOMAIN"), "", gpc.UseAnyDC);
        GPMGMTLib.GPMSearchCriteria searchOBJ = gpm.CreateSearchCriteria();
        searchOBJ.Add(gpc.SearchPropertyGPODisplayName, gpc.SearchOpEquals, strGPO);
        GPMGMTLib.GPMGPOCollection objGPOlist = gpd.SearchGPOs(searchOBJ);
        GPMGMTLib.GPMSOM gpSom = gpd.GetSOM(strOU);
        GPMGMTLib.GPMGPO gpo = gpd.CreateGPO();
        gpSom.CreateGPOLink(-1,objGPOlist[1]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:17:21+00:00Added an answer on May 20, 2026 at 5:17 pm

    Take a look at this link

    It contains a lot of sample scripts, you will need to add a reference (COM) to GPO Admin 1.0 Type Library from GPOAdmin.dll.

    There is a similar issue discussed here with a sample script in C#

    EDIT:

    Reference gpmgmt.dll as COM interop and use the code as below:

    Public Function CreateAndLinkGPO(ByVal strDomain As String, ByVal strOU As String, ByVal strGPOName As String)
        Dim gpm As New GPM()
        Dim gpmConst As GPMConstants = gpm.GetConstants()
        Dim domain As GPMDomain = gpm.GetDomain(strDomain, "", gpmConst.UseAnyDC)
        Dim som As GPMSOM = domain.GetSOM(strOU)
    
        'create new GPO
        Dim gpo As GPMGPO = domain.CreateGPO()
        gpo.DisplayName = strGPOName 
    
        'create link to OU
        som.CreateGPOLink(-1, gpo)
    
        CreateAndLinkGPO = gpo
    End Function
    

    This is in VB.NET, but can be easily ported to C# posted by a MSFT poster from here. I think the key is .CreateGPOLink, GPMSOM is your OU (Retrieves the IGPMSOM interface that represents the domain or the organizational unit (OU) at the specified path.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I set some group policy rule or mechanism to make sure that
I'm trying to reorder/group a set of results using SQL. I have a few
I have a group of checkboxes that I only want to allow a set
Possible Duplicate: Retrieving the last record in each group I have two tables set
In group expert options I have set Keep Group Together, which makes sure a
I'm using Zend_Form to output a set group of checkboxes: <label style=white-space: nowrap;><input type=checkbox
I'm trying to set the group type for a new Active Directory Entry via
I'm trying to group a set of data based on the range of an
struct Group { Group(string _N, set <string> M_) {Name = N_; Member = M_}
Is there a way to set up a user group that has permissions to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.