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