Joining two tables in WQL/SCCM

穿精又带淫゛_ 提交于 2019-12-11 02:44:05

问题


I think I'm being really stupid here.

I'm using vbscript. I've connected to an SCCM server

Set locator = CreateObject("WbemScripting.SWbemLocator")
Set connection  = locator.ConnectServer("SERVERNAME", "Root\SMS\SITENAME")

I then have a WMI WQL query:

Set Collections = connection.ExecQuery("SELECT LastStatusTime,AdvertisementID,
  LastStateName,AdvertisementName 
  FROM SMS_ClientAdvertisementStatus 
  INNER JOIN SMS_Advertisement 
  ON SMS_Advertisement.AdvertisementID = SMS_ClientAdvertisementStatus.AdvertisementID 
  WHERE  LastStateName = 'Succeeded' 
  AND LastStatusTime > '2012-09-25'")

FOR each Collection in Collections 

        Collection.LastStatusTime 
        Collection.AdvertisementID

Next

I think there's a gap in my understanding of WQL. I seem to be able to join these two WQL "tables" in this query, but I can only return values from SMS_ClientAdvertisementStatus.

If I try to return anything from SMS_Advertisement, the table I've joined, I just get an error.

Can you join "tables" in WQL - if they even are tables? Or do I have to have a nested query? Or is there another way of returning data from two tables?


回答1:


WQL doesn't support JOINs, but you can use MOF to define WMI classes that contain data from multiple classes. See here:

Creating a New Instance from Old Properties




回答2:


The WQL language is just a subset of SQL and doesn't supports the JOIN statement, instead you can use the ASSOCIATORS OF in some cases.




回答3:


WQL does support joins. Here is a sample working query, which lists the names of devices which match with collection names. Works in SCCM 2012.

select SMS_R_SYSTEM.Name from SMS_R_System inner join SMS_Collection as Systems on Systems.Name = SMS_R_System.Name



回答4:


I had a similar issue when trying to use JOIN statements in my PowerShell SCCM / ConfigManager queries and found this to be a great solution:

https://gallery.technet.microsoft.com/scriptcenter/SCCM-2012-WMI-query-with-0daea30c#content

I believe the methods could translate to other languages too.



来源:https://stackoverflow.com/questions/12583601/joining-two-tables-in-wql-sccm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!