C#在AD中创建GPO

时间:2013-07-18 11:59:25

标签: c# dns gpo

我创建了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);
    }

当我点击按钮时,我遇到错误“GPMSOM som = gpd.GetSOM(strOU);” - “HRESULT异常:0x8007202B” 我是域管理员。当我省略下面的行时,将创建策略,但仍会显示错误。 请帮忙,谢谢!

0 个答案:

没有答案