{"id":1354,"date":"2014-06-09T12:17:31","date_gmt":"2014-06-09T04:17:31","guid":{"rendered":"http:\/\/www.jhouseconsulting.com\/?p=1354"},"modified":"2014-06-09T12:22:24","modified_gmt":"2014-06-09T04:22:24","slug":"script-to-create-import-and-export-group-policy-wmi-filters","status":"publish","type":"post","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2014\/06\/09\/script-to-create-import-and-export-group-policy-wmi-filters-1354","title":{"rendered":"Script to Create, Import and Export Group Policy WMI Filters"},"content":{"rendered":"<p>This PowerShell script will Create, Import and Export Group Policy WMI Filters.<\/p>\n<p>I wrote this script to cover a number of different scenarios:<\/p>\n<ul>\n<li>To create a default set of GPO WMI Filters for new builds.<\/li>\n<li>To document existing WMI filters for health checks and audits.<\/li>\n<li>To provide a mechanism to migrate WMI filters between Dev, Test, QA and Prod.<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p>The following screen shot shows the default set of GPO WMI Filters that I typically use.<\/p>\n<p><a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/Default-GPO-WMI-Filters.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-1355\" src=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/Default-GPO-WMI-Filters.png\" alt=\"Default GPO WMI Filters\" width=\"642\" height=\"100\" srcset=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/Default-GPO-WMI-Filters.png 1200w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/Default-GPO-WMI-Filters-300x47.png 300w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/Default-GPO-WMI-Filters-768x120.png 768w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/Default-GPO-WMI-Filters-1024x160.png 1024w\" sizes=\"(max-width: 642px) 100vw, 642px\" \/><\/a><\/p>\n<p>The following screen shot shows how they look from within the GPMC.<\/p>\n<p><a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/GPO-WMI-Filters.png\"><img decoding=\"async\" class=\"aligncenter wp-image-1356\" src=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/GPO-WMI-Filters.png\" alt=\"GPO WMI Filters\" width=\"639\" height=\"320\" srcset=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/GPO-WMI-Filters.png 917w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/GPO-WMI-Filters-300x150.png 300w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/GPO-WMI-Filters-768x384.png 768w\" sizes=\"(max-width: 639px) 100vw, 639px\" \/><\/a><\/p>\n<p>These particular WMI queries are not performance intensive, and therefore quick to process. However, it&#8217;s important to be careful how you construct them, as WMI is often known to be slow and inefficient. And of course a corrupt or inconsistent\u00a0WMI repository doesn&#8217;t help.<\/p>\n<p>As always it is recommended to use a tool such as the <a href=\"http:\/\/gpoguy.com\/free-tools\/free-tools-library\/wmi-filter-validation-utility\/\" target=\"_blank\">WMI Filter Validation Utility<\/a> to ensure the WMI query is valid and efficient.<\/p>\n<p>Here are the contents of the\u00a0<a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/DefaultWMIFilters.csv.txt\" target=\"_blank\">DefaultWMIFilters.csv<\/a> file that can be used to create\u00a0the default set of filters I use.<\/p>\n<p>Here is the <a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2014\/06\/ManageWMIFilters.ps1_.txt\" target=\"_blank\">ManageWMIFilters.ps1<\/a>\u00a0script:<\/p>\n<pre class=\"brush: powershell; auto-links: false; title: ; toolbar: false; notranslate\" title=\"\">\r\n&lt;#\r\n  This script will Create, Import and Export Group Policy WMI Filters\r\n\r\n  Syntax examples:\r\n    Create:\r\n      ManageWMIFilters.ps1 -Action Create -ReferenceFile DefaultWMIFilters.csv\r\n    Export:\r\n      ManageWMIFilters.ps1 -Action Export -ReferenceFile WMIFiltersExport.csv\r\n    Import:\r\n      ManageWMIFilters.ps1 -Action Import -ReferenceFile WMIFiltersExport.csv\r\n\r\n  It was originally based on the following three scripts:\r\n    1) Using Powershell to Automatically Create WMI Filters:\r\n       http:\/\/gallery.technet.microsoft.com\/scriptcenter\/f1491111-9f5d-4c83-b436-537eca9e8d94\r\n    2) Exporting and Importing WMI Filters with PowerShell: Part 1, Export:\r\n       http:\/\/blogs.technet.com\/b\/manny\/archive\/2012\/02\/04\/perform-a-full-export-and-import-of-wmi-filters-with-powershell.aspx\r\n    3) Exporting and Importing WMI Filters with PowerShell: Part 2, Import:\r\n       http:\/\/blogs.technet.com\/b\/manny\/archive\/2012\/02\/05\/exporting-and-importing-wmi-filters-with-powershell-part-2-import.aspx\r\n\r\n  Another great reference:\r\n  - Digging Into Group Policy WMI Filters and Managing them through PowerShell\r\n    http:\/\/sdmsoftware.com\/group-policy-blog\/gpmc\/digging-into-group-policy-wmi-filters-and-managing-them-through-powershell\/\r\n\r\n  I left the code as 3 separate modules so that it can be easily split and\r\n  reused if preferred. Hence the reason why there is currently some duplicate\r\n  code between the create and import sections.\r\n\r\n  Modified all code to completely remove the requirement for the Active\r\n  Directory PowerShell Module.\r\n\r\n  Fixed an issue where it was not calculating the length of the supplied\r\n  namespace. ie. The script would only import correctly if the namespace was\r\n  root\\CIMv2. But when using the root\\virtualization namespace it would fail.\r\n  This is actually an error found in all GPO WMI creation script I've found.\r\n  They all assume that root\\CIMv2 is the only namespace used.\r\n\r\n  If your Active Directory is based on Windows 2003 or has been upgraded\r\n  from Windows 2003, you may may have an issue with System Owned Objects.\r\n  Importing or adding a WMI Filter object into AD used to be a system only\r\n  operation. So you previously needed to enable system only changes on a\r\n  domain controller for a successful ldifde import.\r\n  If this is the case you will need to set the following registry value:\r\n    Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\NTDS\\Parameters\r\n    Type: REG_DWORD\r\n    Value: Allow System Only Change\r\n    Data: 1\r\n\r\n  Release 1.3\r\n  Written by Jeremy@jhouseconsulting.com 11th September 2013\r\n  Modified by Jeremy@jhouseconsulting.com 9th June 2014\r\n\r\n#&gt;\r\n\r\n#-------------------------------------------------------------\r\nparam(&#x5B;String]$Action,&#x5B;String]$ReferenceFile)\r\n\r\nWrite-Host -ForegroundColor Green &quot;Verifying script parameters...`n&quot;\r\n\r\n$helptext = $False\r\n\r\nif (&#x5B;String]::IsNullOrEmpty($Action)) {\r\n  write-host -ForeGroundColor Red &quot;Action is a required parameter.`n&quot;\r\n  $helptext = $True\r\n} else {\r\n  switch ($Action)\r\n  {\r\n    &quot;Create&quot; {$Create = $true;$Import = $false;$Export = $false}\r\n    &quot;Import&quot; {$Create = $false;$Import = $true;$Export = $false}\r\n    &quot;Export&quot; {$Create = $false;$Import = $false;$Export = $true}\r\n    default {$Create = $false;$Import = $false;$Export = $false}\r\n  }\r\n  if ($Create -eq $false -AND $Import -eq $false -AND $Export -eq $false) {\r\n    write-host -ForeGroundColor Red &quot;The Action parameter is invalid.`n&quot;\r\n    $helptext = $True\r\n  }\r\n}\r\n\r\nif (&#x5B;String]::IsNullOrEmpty($ReferenceFile)) {\r\n  write-host -ForeGroundColor Red &quot;ReferenceFile is a required parameter. Exiting Script.`n&quot;\r\n  $helptext = $True\r\n}\r\n\r\nIf ($helptext) {\r\n  $Message = &quot;Syntax examples:&quot;\r\n  $Message = $Message + &quot;`n`tCreate:&quot;\r\n  $Message = $Message + &quot;`n`t`tManageWMIFilters.ps1 -Action Create -ReferenceFile DefaultWMIFilters.csv&quot;\r\n  $Message = $Message + &quot;`n`tExport:&quot;\r\n  $Message = $Message + &quot;`n`t`tManageWMIFilters.ps1 -Action Export -ReferenceFile WMIFiltersExport.csv&quot;\r\n  $Message = $Message + &quot;`n`tImport:&quot;\r\n  $Message = $Message + &quot;`n`t`tManageWMIFilters.ps1 -Action Import -ReferenceFile WMIFiltersExport.csv&quot;\r\n  write-host -ForeGroundColor Green $Message\r\n  write-host -ForeGroundColor Red &quot;`nExiting Script.&quot;\r\n  Exit\r\n}\r\n\r\n#-------------------------------------------------------------\r\n\r\n# Set this to true to set the Allow System Only Change registry value\r\n$EnableAllowSystemOnlyChange = $False\r\n\r\n#-------------------------------------------------------------\r\nfunction Enable-ADSystemOnlyChange(&#x5B;switch] $disable)\r\n{\r\n    # This function has been taken directly from the GPWmiFilter.psm1\r\n    # module written by Bin Yi from Microsoft.\r\n    $valueData = 1\r\n    if ($disable)\r\n    {\r\n        $valueData = 0\r\n    }\r\n    $key = Get-Item HKLM:\\System\\CurrentControlSet\\Services\\NTDS\\Parameters -ErrorAction SilentlyContinue\r\n    if (!$key) {\r\n        New-Item HKLM:\\System\\CurrentControlSet\\Services\\NTDS\\Parameters -ItemType RegistryKey | Out-Null\r\n    }\r\n    $kval = Get-ItemProperty HKLM:\\System\\CurrentControlSet\\Services\\NTDS\\Parameters -Name &quot;Allow System Only Change&quot; -ErrorAction SilentlyContinue\r\n    if (!$kval) {\r\n        New-ItemProperty HKLM:\\System\\CurrentControlSet\\Services\\NTDS\\Parameters -Name &quot;Allow System Only Change&quot; -Value $valueData -PropertyType DWORD | Out-Null\r\n    } else {\r\n        Set-ItemProperty HKLM:\\System\\CurrentControlSet\\Services\\NTDS\\Parameters -Name &quot;Allow System Only Change&quot; -Value $valueData | Out-Null\r\n    }\r\n}\r\n\r\n#-------------------------------------------------------------\r\nIf ($Import -eq $true) {\r\n\r\n  if ((Test-Path $ReferenceFile) -eq $False) {\r\n    Write-Host -ForegroundColor Red &quot;The $ReferenceFile file is missing. Cannot import WMI Filters.`n&quot;\r\n    exit\r\n  }\r\n\r\n  $Header = &quot;Name&quot;,&quot;Description&quot;,&quot;Filter&quot;\r\n  $WMIFilters = import-csv $ReferenceFile -Delimiter &quot;`t&quot; -Header $Header\r\n\r\n  $RowCount = $WMIFilters | Measure-Object | Select-Object -expand count\r\n\r\n  if ($RowCount -gt 0) {\r\n\r\n    write-host -ForeGroundColor Green &quot;Importing $RowCount WMI Filters`n&quot;\r\n\r\n    $Domain = &#x5B;System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()\r\n    $DomainName = $Domain.Name\r\n    $DomainDistinguishedName = $Domain.GetDirectoryEntry() | Select-Object -ExpandProperty DistinguishedName\r\n\r\n    $UseAdministrator = $False\r\n    If ($UseAdministrator -eq $False) {\r\n      $msWMIAuthor = &#x5B;System.Security.Principal.WindowsIdentity]::GetCurrent().Name\r\n    } Else {\r\n      $msWMIAuthor = &quot;Administrator@&quot; + $DomainName\r\n    }\r\n\r\n    foreach ($WMIFilter in $WMIFilters) {\r\n      $WMIGUID = &#x5B;string]&quot;{&quot;+(&#x5B;System.Guid]::NewGuid())+&quot;}&quot;\r\n      $WMIDN = &quot;CN=&quot;+$WMIGUID+&quot;,CN=SOM,CN=WMIPolicy,CN=System,&quot;+$DomainDistinguishedName\r\n      $WMICN = $WMIGUID\r\n      $WMIdistinguishedname = $WMIDN\r\n      $WMIID = $WMIGUID\r\n\r\n      $now = (Get-Date).ToUniversalTime()\r\n      $msWMICreationDate = ($now.Year).ToString(&quot;0000&quot;) + ($now.Month).ToString(&quot;00&quot;) + ($now.Day).ToString(&quot;00&quot;) + ($now.Hour).ToString(&quot;00&quot;) + ($now.Minute).ToString(&quot;00&quot;) + ($now.Second).ToString(&quot;00&quot;) + &quot;.&quot; + ($now.Millisecond * 1000).ToString(&quot;000000&quot;) + &quot;-000&quot;\r\n      $msWMIName = $WMIFilter.Name\r\n      $msWMIParm1 = $WMIFilter.Description + &quot; &quot;\r\n      $msWMIParm2 = $WMIFilter.Filter\r\n\r\n      $array = @()\r\n      $SearchRoot = &#x5B;adsi](&quot;LDAP:\/\/CN=SOM,CN=WMIPolicy,CN=System,&quot;+$DomainDistinguishedName)\r\n      $search = new-object System.DirectoryServices.DirectorySearcher($SearchRoot)\r\n      $search.filter = &quot;(objectclass=msWMI-Som)&quot;\r\n      $results = $search.FindAll()\r\n      ForEach ($result in $results) {\r\n        $array += $result.properties&#x5B;&quot;mswmi-name&quot;].item(0)\r\n      }\r\n\r\n      if ($array -notcontains $msWMIName) {\r\n        write-host -ForeGroundColor Green &quot;Importing the $msWMIName WMI Filter from $ReferenceFile`n&quot;\r\n        If ($EnableAllowSystemOnlyChange) {\r\n          Enable-ADSystemOnlyChange\r\n        }\r\n        $SOMContainer = &#x5B;adsi](&quot;LDAP:\/\/CN=SOM,CN=WMIPolicy,CN=System,&quot;+$DomainDistinguishedName)\r\n        $NewWMIFilter = $SOMContainer.create('msWMI-Som',&quot;CN=&quot;+$WMIGUID)\r\n        $NewWMIFilter.put(&quot;msWMI-Name&quot;,$msWMIName)\r\n        $NewWMIFilter.put(&quot;msWMI-Parm1&quot;,$msWMIParm1)\r\n        $NewWMIFilter.put(&quot;msWMI-Parm2&quot;,$msWMIParm2)\r\n        $NewWMIFilter.put(&quot;msWMI-Author&quot;,$msWMIAuthor)\r\n        $NewWMIFilter.put(&quot;msWMI-ID&quot;,$WMIID)\r\n        $NewWMIFilter.put(&quot;instanceType&quot;,4)\r\n        $NewWMIFilter.put(&quot;showInAdvancedViewOnly&quot;,&quot;TRUE&quot;)\r\n        $NewWMIFilter.put(&quot;distinguishedname&quot;,$WMIdistinguishedname)\r\n        $NewWMIFilter.put(&quot;msWMI-ChangeDate&quot;,$msWMICreationDate)\r\n        $NewWMIFilter.put(&quot;msWMI-CreationDate&quot;,$msWMICreationDate)\r\n        $NewWMIFilter.setinfo()\r\n      } Else {\r\n        write-host -ForeGroundColor Yellow &quot;The $msWMIName WMI Filter already exists`n&quot;\r\n      }\r\n    }\r\n  } else {\r\n    Write-Host -ForegroundColor Red &quot;The data in the $ReferenceFile file is missing.`n&quot;\r\n  }\r\n}\r\n\r\n#-------------------------------------------------------------\r\nIf ($Export -eq $true) {\r\n\r\n  set-content $ReferenceFile $NULL\r\n\r\n  $WMIFilters = @()\r\n\r\n  $Domain = &#x5B;System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()\r\n  $DomainName = $Domain.Name\r\n  $DomainDistinguishedName = $Domain.GetDirectoryEntry() | Select-Object -ExpandProperty DistinguishedName\r\n  $SearchRoot = &#x5B;adsi](&quot;LDAP:\/\/CN=SOM,CN=WMIPolicy,CN=System,&quot;+$DomainDistinguishedName)\r\n  $search = new-object System.DirectoryServices.DirectorySearcher($SearchRoot)\r\n  $search.filter = &quot;(objectclass=msWMI-Som)&quot;\r\n  $results = $search.FindAll()\r\n  ForEach ($result in $results) {\r\n    $obj = New-Object -TypeName PSObject\r\n    $obj | Add-Member -MemberType NoteProperty -Name &quot;DistinguishedName&quot; -value $result.properties&#x5B;&quot;distinguishedname&quot;].item(0)\r\n    $obj | Add-Member -MemberType NoteProperty -Name &quot;msWMI-Name&quot; -value $result.properties&#x5B;&quot;mswmi-name&quot;].item(0)\r\n    $obj | Add-Member -MemberType NoteProperty -Name &quot;msWMI-Parm1&quot; -value $result.properties&#x5B;&quot;mswmi-parm1&quot;].item(0)\r\n    $obj | Add-Member -MemberType NoteProperty -Name &quot;msWMI-Parm2&quot; -value $result.properties&#x5B;&quot;mswmi-parm2&quot;].item(0)\r\n    $obj | Add-Member -MemberType NoteProperty -Name &quot;Name&quot; -value $result.properties&#x5B;&quot;name&quot;].item(0)\r\n    $WMIFilters += $obj\r\n  }\r\n\r\n  $RowCount = $WMIFilters | Measure-Object | Select-Object -expand count\r\n\r\n  if ($RowCount -ne 0) {\r\n    write-host -ForeGroundColor Green &quot;Exporting $RowCount WMI Filters`n&quot;\r\n\r\n    foreach ($WMIFilter in $WMIFilters) {\r\n      write-host -ForeGroundColor Green &quot;Exporting the&quot; $WMIFilter.&quot;msWMI-Name&quot; &quot;WMI Filter to $ReferenceFile`n&quot;\r\n      $NewContent = $WMIFilter.&quot;msWMI-Name&quot; + &quot;`t&quot; + $WMIFilter.&quot;msWMI-Parm1&quot; + &quot;`t&quot; + $WMIFilter.&quot;msWMI-Parm2&quot;\r\n      add-content $NewContent -path $ReferenceFile\r\n    }\r\n    write-host -ForeGroundColor Green &quot;An export of the WMI Filters has been stored at $ReferenceFile`n&quot;\r\n\r\n  } else {\r\n    write-host -ForeGroundColor Green &quot;There are no WMI Filters to export`n&quot;\r\n  }\r\n}\r\n\r\n#-------------------------------------------------------------\r\nIf ($Create -eq $true) {\r\n\r\n  if ((Test-Path $ReferenceFile) -eq $False) {\r\n    Write-Host -ForegroundColor Red &quot;The $ReferenceFile file is missing. Cannot create WMI Filters.`n&quot;\r\n    exit\r\n  }\r\n\r\n  $Domain = &#x5B;System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()\r\n  $DomainName = $Domain.Name\r\n  $DomainDistinguishedName = $Domain.GetDirectoryEntry() | Select-Object -ExpandProperty DistinguishedName\r\n\r\n  $UseAdministrator = $False\r\n  If ($UseAdministrator -eq $False) {\r\n    $msWMIAuthor = &#x5B;System.Security.Principal.WindowsIdentity]::GetCurrent().Name\r\n  } Else {\r\n    $msWMIAuthor = &quot;Administrator@&quot; + $DomainName\r\n  }\r\n\r\n  # Import WMI Filters From CSV\r\n  # Name,Description,Filter\r\n  $WMIFilters = import-csv $ReferenceFile\r\n\r\n  $RowCount = $WMIFilters | Measure-Object | Select-Object -expand count\r\n\r\n  if ($RowCount -gt 0) {\r\n\r\n    write-host -ForeGroundColor Green &quot;Creating $RowCount WMI Filters`n&quot;\r\n\r\n    foreach ($WMIFilter in $WMIFilters) {\r\n      $WMIGUID = &#x5B;string]&quot;{&quot;+(&#x5B;System.Guid]::NewGuid())+&quot;}&quot;\r\n      $WMIDN = &quot;CN=&quot;+$WMIGUID+&quot;,CN=SOM,CN=WMIPolicy,CN=System,&quot;+$DomainDistinguishedName\r\n      $WMICN = $WMIGUID\r\n      $WMIdistinguishedname = $WMIDN\r\n      $WMIID = $WMIGUID \r\n\r\n      $now = (Get-Date).ToUniversalTime()\r\n      $msWMICreationDate = ($now.Year).ToString(&quot;0000&quot;) + ($now.Month).ToString(&quot;00&quot;) + ($now.Day).ToString(&quot;00&quot;) + ($now.Hour).ToString(&quot;00&quot;) + ($now.Minute).ToString(&quot;00&quot;) + ($now.Second).ToString(&quot;00&quot;) + &quot;.&quot; + ($now.Millisecond * 1000).ToString(&quot;000000&quot;) + &quot;-000&quot; \r\n\r\n      $msWMIName = $WMIFilter.Name\r\n      $msWMIParm1 = $WMIFilter.Description + &quot; &quot;\r\n      $msWMIParm2 = &quot;1;3;&quot; + $WMIFilter.Namespace.Length.ToString() + &quot;;&quot; + $WMIFilter.Query.Length.ToString() + &quot;;WQL;&quot; + $WMIFilter.Namespace + &quot;;&quot; + $WMIFilter.Query + &quot;;&quot;\r\n\r\n      $array = @()\r\n      $SearchRoot = &#x5B;adsi](&quot;LDAP:\/\/CN=SOM,CN=WMIPolicy,CN=System,&quot;+$DomainDistinguishedName)\r\n      $search = new-object System.DirectoryServices.DirectorySearcher($SearchRoot)\r\n      $search.filter = &quot;(objectclass=msWMI-Som)&quot;\r\n      $results = $search.FindAll()\r\n      ForEach ($result in $results) {\r\n        $array += $result.properties&#x5B;&quot;mswmi-name&quot;].item(0)\r\n      }\r\n\r\n      if ($array -notcontains $msWMIName) {\r\n        write-host -ForeGroundColor Green &quot;Creating the $msWMIName WMI Filter from $ReferenceFile`n&quot;\r\n        If ($EnableAllowSystemOnlyChange) {\r\n          Enable-ADSystemOnlyChange\r\n        }\r\n        $SOMContainer = &#x5B;adsi](&quot;LDAP:\/\/CN=SOM,CN=WMIPolicy,CN=System,&quot;+$DomainDistinguishedName)\r\n        $NewWMIFilter = $SOMContainer.create('msWMI-Som',&quot;CN=&quot;+$WMIGUID)\r\n        $NewWMIFilter.put(&quot;msWMI-Name&quot;,$msWMIName)\r\n        $NewWMIFilter.put(&quot;msWMI-Parm1&quot;,$msWMIParm1)\r\n        $NewWMIFilter.put(&quot;msWMI-Parm2&quot;,$msWMIParm2)\r\n        $NewWMIFilter.put(&quot;msWMI-Author&quot;,$msWMIAuthor)\r\n        $NewWMIFilter.put(&quot;msWMI-ID&quot;,$WMIID)\r\n        $NewWMIFilter.put(&quot;instanceType&quot;,4)\r\n        $NewWMIFilter.put(&quot;showInAdvancedViewOnly&quot;,&quot;TRUE&quot;)\r\n        $NewWMIFilter.put(&quot;distinguishedname&quot;,$WMIdistinguishedname)\r\n        $NewWMIFilter.put(&quot;msWMI-ChangeDate&quot;,$msWMICreationDate)\r\n        $NewWMIFilter.put(&quot;msWMI-CreationDate&quot;,$msWMICreationDate)\r\n        $NewWMIFilter.setinfo()\r\n      } Else {\r\n        write-host -ForeGroundColor Yellow &quot;The $msWMIName WMI Filter already exists`n&quot;\r\n      }\r\n    }\r\n  } else {\r\n    Write-Host -ForegroundColor Red &quot;The data in the $ReferenceFile file is missing.`n&quot;\r\n  }\r\n}\r\n<\/pre>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This PowerShell script will Create, Import and Export Group Policy WMI Filters. I wrote this script to cover a number of different scenarios: To create a default set of GPO WMI Filters for new builds. To document existing WMI filters for health checks and audits. To provide a mechanism to migrate WMI filters between Dev, &#8230; <a title=\"Script to Create, Import and Export Group Policy WMI Filters\" class=\"read-more\" href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2014\/06\/09\/script-to-create-import-and-export-group-policy-wmi-filters-1354\" aria-label=\"Read more about Script to Create, Import and Export Group Policy WMI Filters\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[202,60,5],"tags":[428,284,337,343,345,214,347,419,346,344,341,340,349,348,350],"class_list":["post-1354","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-group-policy","category-scripting","tag-active-directory","tag-ad","tag-adds","tag-create","tag-export","tag-gpo","tag-gpo-wmi-filters","tag-group-policy","tag-group-policy-wmi-filters","tag-import","tag-posh","tag-powershell","tag-som","tag-wmi-filters","tag-wmipolicy"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/1354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/comments?post=1354"}],"version-history":[{"count":7,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/1354\/revisions"}],"predecessor-version":[{"id":1365,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/1354\/revisions\/1365"}],"wp:attachment":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/media?parent=1354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/categories?post=1354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/tags?post=1354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}