简体   繁体   English

SCCM查询过滤器

[英]SCCM Query Filter

I am trying to write a query in SCCM to look for .Net Framework that is less than a certain version. 我试图在SCCM中编写查询以查找小于特定版本的.Net Framework。

What I have: 我有的:

select distinct SMS_R_System.Name from  SMS_R_System where SMS_R_System.Name not in (select distinct SMS_R_System.Name from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceId = SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = "Microsoft .NET Framework 4.6.2")

This shows everything not named 4.6.2. 这显示了所有未命名的4.6.2。 I want it to display everything less than 4.6.2. 我希望它显示小于4.6.2的所有内容。 Also, when the query is ran, it shows only the machine name. 此外,运行查询时,它仅显示计算机名称。 What is the best way to display not just the machine name, but what version is installed? 不仅显示计算机名称,而且显示安装的版本的最佳方法是什么?

The WQL Query would be WQL查询将是

select distinct SMS_R_System.Name, SMS_G_System_ADD_REMOVE_PROGRAMS.Version from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceId = SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like 'Microsoft .NET Framework 4%'  and Version < '4.6.2'

There are however several caveats. 但是,有几个警告。 The first is that the less than for the version is just a string compare. 首先是小于版本号只是一个字符串比较。 This means version 10 is smaller than 4 and 4.10 smaller than 4.6. 这意味着版本10小于4,版本4.10小于4.6。 However as we know the range of the .NET Versions and we know that those do not exist I think it should be fine. 但是,由于我们知道.NET版本的范围,并且我们知道这些版本不存在,所以我认为应该没问题。 If you want to be sure you would have to use some programming language to further split the version into its parts and analyze them. 如果要确定,则必须使用某种编程语言将版本进一步拆分为各个部分并进行分析。

Another is that this only checks for version 4 in general. 另一个是,这通常只检查版本4。 This is because version 1 can be installed alongside version 4 and you would get every computer listed in the results. 这是因为版本1可以与版本4一起安装,并且您将获得结果中列出的每台计算机。 However as .NET works in a special way where version 1 is often installed alongside version 4 but version 2 and 3 are not it could lead to problems if you have really old installations. 但是,由于.NET以一种特殊的方式工作,其中版本1经常与版本4并排安装,而版本2和3却没有,因此如果您安装的确实很旧,可能会导致问题。 As this would mean pre Windows 7 installations I assumed it is probably no problem in your case. 因为这意味着Windows 7之前的安装,所以我认为在您的情况下可能没有问题。

The last thing is that unforutnately WQL is not SQL and behaves really crazy if you join classes and take information form both. 最后一件事是,不幸的是,WQL不是SQL,并且如果您加入类并同时从两者中获取信息,那么它们的表现会非常疯狂。 So if you execute this query in some WMI Tool there is a high chance you get a result like System.Management.ManagementBaseObject instead of the results you want. 因此,如果您在某些WMI工具中执行此查询,则很有可能会得到诸如System.Management.ManagementBaseObject之类的结果,而不是您想要的结果。 To avoid this you can use powershell to execute the query like this: 为了避免这种情况,您可以使用powershell来执行查询,如下所示:

$computername = "<SiteServer>"
$namespace = 'Root\SMS\site_<SiteCode>'
$query = "select distinct SMS_R_System.Name, SMS_G_System_ADD_REMOVE_PROGRAMS.Version from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceId = SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like 'Microsoft .NET Framework 4%'  and SMS_G_System_ADD_REMOVE_PROGRAMS.Version < '4.6.2'"

gwmi -ComputerName $computername -Namespace $namespace -Query $query | Select-Object -Property @{n='Name';e={$_.SMS_R_System.Name}}, @{n='Version';e={$_.SMS_G_System_ADD_REMOVE_PROGRAMS.Version}}

Finally if you have access to the SCCM DB you could also use SQL instead of WQL which is a lot faster and allows for better joining. 最后,如果您有权访问SCCM DB,则也可以使用SQL代替WQL,这要快得多,并且可以更好地进行连接。 If this is a possibility for you I'd recommend it for quick queries/lookups over WQL. 如果您有可能,我建议您通过WQL快速查询/查找。 The classes have a little different names there so the query would be: 这些类的名称稍有不同,因此查询如下:

select distinct v_R_System.Name0, v_Add_Remove_Programs.Version0 
  from 
v_R_System inner join v_Add_Remove_Programs 
  on 
v_Add_Remove_Programs.ResourceId = v_R_System.ResourceId 
  where 
v_Add_Remove_Programs.DisplayName0 like 'Microsoft .NET Framework 4%'  
  and 
v_Add_Remove_Programs.Version0 < '4.6.2'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM