我正在尝试通过C#代码使用GPMC COM对象以编程方式创建GPO。我可以创建GPO,但是我在使用GPO“插入”WMI过滤器时遇到了麻烦。有谁知道如何为GPO创建/更新WMI过滤器?
答案 0 :(得分:1)
以下是示例代码:
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