我正在尝试通过C#代码使用GPMC COM对象以编程方式创建GPO。我可以创建GPO,但是在用GPO“插入” WMI筛选器时遇到了麻烦。有谁知道我如何为GPO创建/更新WMI筛选器?
最佳答案
这是示例代码:
GPMGMTLib.GPM gPM = new GPMGMTLib.GPM();
GPMConstants gPMConstants = gPM.GetConstants();
GPMDomain gPMDomain = gPM.GetDomain(domainName, DC, gPMConstants.UseAnyDC);
GPMGPO obj = gPMDomain.CreateGPO();
obj.DisplayName = "New GPO";
//replace with the appropiate GUID
var strWMIFilterID = "{D715559A-7965-45A6-864D-AEBDD9934415}";
var sWMIFilter = string.Format("MSFT_SomFilter.Domain=\"{0}\",ID=\"{1}\"", domainName, strWMIFilterID);
var oWMIFilter = gPMDomain.GetWMIFilter(sWMIFilter);
obj.SetWMIFilter(oWMIFilter);
以下是带有其他信息的链接:
WMIFilters
Active Directory Cookbook