C# Create GPO in AD

0

I create GPO

private void button5_Click(object sender, EventArgs e)
    {
        CreateAndLinkGPO(domain, "OU=Company,OU=Users,OU=Users,DC=Company.local,DC=net", "new_test_policy");
    }

    public void CreateAndLinkGPO(string strDomain, string strOU, string strGPOName)
    {
        GPM gpm = new GPMGMTLib.GPM();
        IGPMConstants gpc = gpm.GetConstants();
        IGPMDomain gpd = gpm.GetDomain(Environment.GetEnvironmentVariable("USERDNSDOMAIN"), "", gpc.UseAnyDC);
        GPMSOM som = gpd.GetSOM(strOU);

        GPMSearchCriteria gps = gpm.CreateSearchCriteria();
        IGPMGPOCollection gpoc = gpd.SearchGPOs(gps);

        IGPMGPO gpo = gpd.CreateGPO();
        gpo.DisplayName = strGPOName;

        som.CreateGPOLink(-1, gpo);
    }

and when i'm click button, i have error at line "GPMSOM som = gpd.GetSOM(strOU);" - "Exception from HRESULT: 0x8007202B" I'm domain administrator. when I omit the line below, the policy is created, but the error is still displayed. please help, thank!

c#
dns
gpo

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0