How to create a WMI filter in GPO via C #

I am trying to create a GPO programmatically using a GPMC COM object through C # code. I can create a GPO, but I had a problem with the "insertion" of a WMI filter with a GPO. Does anyone know how I can create / update WMI filters for GPOs?

+3
source share
1 answer

Here is an example code:

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

Here are some links with more information:
WMIFilters
Active Directory Account

+1
source

Source: https://habr.com/ru/post/1707133/


All Articles