2011-03-15 16 views
6

¿Cómo configuro las políticas de grupo en AD? Puedo crear mi unidad organizativa, pero también necesito adjuntar una política de grupo que vincule a ella. Entonces esto es lo que tengo hasta ahora.Política de grupo de enlaces de C# en AD

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); 

Esto todavía no crea el vínculo de GPO, pero todo lo que quiero hacer es vincular un GPO existente, anyt pensamientos? Y gracias por la ayuda.

bien cada vez más cerca, esto acaba de crear una política de no vincular realidad uno ya existente ...

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); 

de actualización y de Trabajo:

Esto es para la vinculación de GPO existente a la unidad organizativa usando C#
1) instalar http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=0a6d4c24-8cbd-4b35-9272-dd3cbfc81887
gpmgmt.dll 2) Referencia (que se encuentra en el directorio de instalación)
3) Es posible que tenga que instalar .Net 1.1
4) Agregue referencias a VS
5) agregue usando GPMGMTLib; usando GPOADMINLib; para proyectar

  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]); 
+0

alguien? esto no puede ser imposible ... –

+0

preguntaste hace 22 minutos. Se paciente. – Amy

+0

so gpd.GETSOM ("Seguridad predeterminada con acceso web") está creando un NUEVO ou? – kd7

Respuesta

4

Tome un vistazo a este link

Contiene una gran cantidad de scripts de ejemplo, necesitará añadir una referencia (COM) a GPO administración 1.0 biblioteca de tipos de GPOAdmin.dll.

Hay un problema similar discutió here con un script de ejemplo en C#

EDITAR:

gpmgmt.dll referencia como interoperabilidad COM y utilizar el código de la siguiente manera:

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 

Esto está en VB.NET, pero se puede portar fácilmente a C# publicado por MSFT poster from here. Creo que la clave es CreateGPOLink, GPMSOM es su unidad organizativa (Recupera la interfaz IGPMSOM que representa el dominio o la unidad organizativa (OU) en la ruta especificada.)

+0

Lo vi, pero ¿cómo lo relacionas con la unidad organizativa? –

+0

Puedo encontrar ese GPO usando ese ejemplo, pero ¿hay algún ejemplo de CopyTo en un GPO específico? –

+0

ver edición si tiene la oportunidad –

2

Estaba buscando una manera de simplemente enumerar los GPO que están vinculados a una OU particular , este hilo me ayudó muchísimo. Tengo el siguiente subtítulo para compartir. No enumera los nombres de los GPO pero devuelve el recuento. Un mod menor le permitirá obtener los nombres (consulte las propiedades de GPOLink en el ciclo foreach). Deberá instalar GPMC y agregar gpmgmt.dll como referencia del proyecto.

private string getGPOLinkCount(string OUPathDN, bool onlyEnabledLinks, bool includeInheritedLinks) 
    { 
     int linkCount = 0; 

     try 
     { 
      GPMGMTLib.GPM gpm = new GPMGMTLib.GPM(); 
      GPMGMTLib.IGPMConstants gpc = gpm.GetConstants(); 
      GPMGMTLib.IGPMDomain gpd = gpm.GetDomain(Environment.GetEnvironmentVariable("USERDNSDOMAIN"), "", gpc.UseAnyDC); 

      GPMGMTLib.GPMSOM gpSom = gpd.GetSOM(OUPathDN); 

      GPMGPOLinksCollection GPOLinks = gpSom.GetGPOLinks(); 
      GPMGPOLinksCollection GPOLinksIncludingInherited = gpSom.GetInheritedGPOLinks(); 


      if (!includeInheritedLinks) 
      { 
       foreach (GPMGPOLink GPOLink in GPOLinks) 
       { 
        if (onlyEnabledLinks) 
        { 
         if (GPOLink.Enabled) 
         { 
          linkCount++; 
         } 
        } 
        if (!onlyEnabledLinks) //Get all links, disabled or enabled 
        { 
         linkCount++; 
        } 
       }     
      } 

      if (includeInheritedLinks) 
      { 
       foreach (GPMGPOLink GPOLink in GPOLinksIncludingInherited) 
       { 
        if (onlyEnabledLinks) 
        { 
         if (GPOLink.Enabled) 
         { 
          linkCount++; 
         } 
        } 
        if (!onlyEnabledLinks) //Get all links, disabled or enabled 
        { 
         linkCount++; 
        } 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      return "GPO links: " + ex.Message.Replace("\r\n", ""); 
     } 

     return linkCount.ToString();    
    } 
Cuestiones relacionadas