C#, Create GPO And link it to OU using Microsoft.GroupPolicy.Management?

别来无恙 提交于 2019-12-22 01:25:36

问题


I've done hard research and trying to solve my problem. 3 days googling and asking now i ended up with this :

using Microsoft.GroupPolicy;

private void ManipulateGPO(){
    GPDomain domain = new GPDomain("sh.dom");
    Gpo gpo_background = domain.CreateGpo("testingGPO");
}

the code above create a GPO successfully. but i need to link it to an OU?

any help will be appreciated.

UPDATE 1: My GPO Screenshot


回答1:


You use the SOM (Scope of Management) class to link to the OU

using Microsoft.GroupPolicy;

private void ManipulateGPO(){
    GPDomain domain = new GPDomain("sh.dom");
    Gpo gpo_background = domain.CreateGpo("testingGPO");
    Som som = domain.GetSom("The path of the SOM specified as a fully qualified distinguished name, for example, (ou=MyOU,dc=contoso,dc=com)");
    som.LinkGpo(-1, gpo_background);
}

References Som Class: https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.grouppolicy.som(v=vs.85).aspx

LinkGpo: https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.grouppolicy.som.linkgpo(v=vs.85).aspx

GPDomain.GetSom: https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.grouppolicy.gpdomain.getsom(v=vs.85).aspx



来源:https://stackoverflow.com/questions/45553917/c-create-gpo-and-link-it-to-ou-using-microsoft-grouppolicy-management

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!