Thursday, October 16, 2014

Configmgr Report - Computers that don't have a specific software installed

Thought i do a short writeup on how to use the mystical sub select query to find computers in a collection that don't have a specific software installed.




Download the RDL and change the "Datasource1"  to suit your environment.




The report uses a simple search filter to limit the number of software titles in the "Select Software" list.



Finding computers with some software installed is easy ,but people often get it wrong when they try to flip the query to find computers without the software.

The query to find computers with a specific software is:

SELECT ResourceID FROM   v_add_remove_programs 
WHERE  displayname0 LIKE '%Java Update 67%'

When people try to change the query to look for computers without some software they try to change the "Like" to "Not Like and expect it to work. The query is valid and will output a list of computers ,but the result will basically be all computers....
To get this to work we need to use a sub-select query.
Subselect querys are not that hard. you just wrap the query to find all computers with Java installed in parentheses and use the where not in clause.
In it's simplest form the sub select query looks like this ,notice the part in the parentheses is the same as above: 

SELECT ResourceID,Name0 FROM v_r_system 
WHERE ResourceID NOT IN
(
    SELECT ResourceID FROM   v_add_remove_programs 
    WHERE  displayname0 LIKE '%Java Update 67%'
)




Main Query for the Report:

SELECT v_r_system.name0, 
       .v_r_system.user_name0, 
       v_gs_operating_system.caption0 
FROM   v_r_system 
       JOIN v_gs_operating_system 
         ON v_r_system.resourceid = v_gs_operating_system.resourceid 
WHERE  v_r_system.resourceid NOT IN (SELECT resourceid 
                                     FROM   v_add_remove_programs 
                                     WHERE  displayname0 LIKE @Software) 
       AND v_r_system.resourceid IN (SELECT resourceid 
                                     FROM   dbo.v_fullcollectionmembership 
                                     WHERE 
           dbo.v_fullcollectionmembership.collectionid 
           = 
           @CollectionID) 

4 comments:

  1. Hi Thomas,
    I really appreciate the time you put in to create these awesome reports.

    Would you please point me to this error I got when running the report?
    "The Value expression for the text box 'Name0' refers to the filed 'Name0'. Report item expressions can only refer to fileds within the current dataset scope or, if inside an aggregate, the specified dataset scope. Letters in the names of fileds must use the correct case"

    ReplyDelete
  2. I'm trying to write a report which shows computers without IE 11. How do I tweak this to show without IE 11?

    select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,
    SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,
    SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_SoftwareFile on SMS_G_System_SoftwareFile.ResourceID = SMS_R_System.ResourceId where SMS_G_System_SoftwareFile.FileName = "iexplore.exe" and SMS_G_System_SoftwareFile.FileVersion like "11.%"

    ReplyDelete
    Replies
    1. since all computers have that file (iexplore.exe) you can get away with just "...and SMS_G_System_SoftwareFile.FileVersion not like "11.%"

      In most cases you would have to use to use a sub-select query like in this blog post.

      Delete
  3. Thanks for the report! I have tried to run this but getting a "Query execution failed for dataset 'mainquery'". Do you know how i can fix this?

    Thanks :)

    ReplyDelete