WMI Query to SCCM 2012 results zero results in c#

In 2007 this works without issues, however in 2012 when attempting the 2nd query it returns zero results.  However if I do this manually I can produce results...Here is my code:
using (WqlConnectionManager connection = Connect(getServer))
   string query = "select * from SMS_ObjectContainerItem WHERE ContainerNodeID='" + ProfileID + "'";              
   foreach (IResultObject getobject in connection.QueryProcessor.ExecuteQuery(query))
     getPackageID = getobject["InstanceKey"].StringValue;
     query = "select * from SMS_Collection WHERE CollectionID='" + getPackageID + "'";
**This is where it will return zero results**
     foreach (IResultObject searchID in connection.QueryProcessor.ExecuteQuery(query))
        CMProfiles profile = new CMProfiles();
        profile.Name = searchID["Name"].StringValue;
        profile.ID = getPackageID;
        results.Add(profile);
I'm pulling my hairs trying to understand by the 2nd query is not returning any results. When this works fine in SCCM 2007

What you are using here are the SDK libraries, which are admittedly very thin wrappers around WMI, but not quite.  Have you tried implementing this directly using WMI?  I have written software that manipulates 2007 / 2012 and eventually found that
the SDK libraries just sort of got in my way, so now I do all of my interactions with SCCM directly with WMI and forgoe the SDK libraries.
Before I changed over, I did find that there are some oddities in using the SDK.  What I eventually found that worked for me was to bind to the 2007 SDK libraries, deliver them with my application and use the 2007 libraries regardless of if I was connecting
to 2007 or 2012.  What I found was that I would run into issues using the 2012 libraries to talk to 2007, but the 2007 libraries would work fine with both.
I have tested your queries, directly using WMI and PowerShell on a 2012 server and they work fine.  I am presuming that the folder that you are attempting to access is a Device Collection folder.
Once again, I would suggest using WMI directly, especially if making a product that will work with 2007 and 2012; you will be a much happier person.
It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

Similar Messages

  • Create a query in SCCM 2012 R2 for NIC Driver Version

    Hello,
        Is there a way to create a query for the specific NIC driver versions with SCCM 2012 R2? For example I can do this and other descriptors for video i.e.,
    select SMS_R_System.Name, SMS_R_System.LastLogonUserName, SMS_R_System.HardwareID, SMS_G_System_COMPUTER_SYSTEM.Manufacturer, SMS_G_System_COMPUTER_SYSTEM.Model, SMS_G_System_VIDEO_CONTROLLER.DriverVersion, SMS_G_System_VIDEO_CONTROLLER.Description, SMS_G_System_VIDEO_CONTROLLER.VideoProcessor
    from  SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_VIDEO_CONTROLLER on SMS_G_System_VIDEO_CONTROLLER.ResourceID = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Model
    like "HP EliteBook Revolve 810 G2" and SMS_G_System_VIDEO_CONTROLLER.Description like "%intel%"
    Is there a script that will give the version for NICs?
    Thanks Bill

    This article provides one way to do it:
    http://blogs.technet.com/b/configmgr_geek_speak/archive/2013/11/10/inventorying-and-reporting-network-adapter-driver-details-and-how-to-report-only-the-wireless-type-in-configuration-manager-2012.aspx
    Jeff

  • System Uptime Query in SCCM 2012 R2

    what is the Query language statement to find the uptime of a system in SCCM 2012 R2? There are so many Object types that it is hard to see if anyone of them has this option.
    Thanks

    SELECT TOP (100) PERCENT dbo.v_R_System.Name0, dbo.v_GS_OPERATING_SYSTEM.LastBootUpTime0, DATEDIFF(Day, dbo.v_GS_OPERATING_SYSTEM.LastBootUpTime0, GETDATE()) AS [Days since last boot],
    dbo.v_GS_OPERATING_SYSTEM.Caption0
    FROM dbo.v_GS_OPERATING_SYSTEM INNER JOIN
    dbo.v_R_System ON dbo.v_GS_OPERATING_SYSTEM.ResourceID = dbo.v_R_System.ResourceID
    WHERE (DATEDIFF(Day, dbo.v_GS_OPERATING_SYSTEM.LastBootUpTime0, GETDATE()) > 7) AND (dbo.v_GS_OPERATING_SYSTEM.Caption0 LIKE '%server%')
    ORDER BY [Days since last boot] DESC
    This is something I built before.
    It shows you server systems that have been online for more than 7 days.
    You can modify it to your needs.

  • Query about SCCM 2012 R2 Client Installation

    Hello I had one SCCM 2012 RTM environment with 1000+ clients,
    Now on the same machine I have uninstalled everything and installed fresh SCCM 2012 R2 software with same site Code etc..
    Kindly suggest me an easy way to upgrade all my SCCM clients to 2012 R2? and How do i verify the same?

    Hi,
     Currently, the clients cannot accept the policies from SCCM 2012 R2 MP, so Push installation, GP installation and manual installation should work. After upgrade, the GUID of clients will remain.
    Juke Chou
    TechNet Community Support

  • Sccm 2012,Result of query is repeating.

    SELECT   
    row_number() over (Order by v_GS_OPERATING_SYSTEM.Caption0) As [S.N],
    dbo.v_R_System.Name0, dbo.v_GS_OPERATING_SYSTEM.Caption0 AS [Operating System],
                           dbo.v_GS_OPERATING_SYSTEM.CSDVersion0 AS [OS Service Pack], arp.DisplayName0,
                            arp.Version0, 
    Dev.[sitecode] as sitename
     FROM         dbo.v_Add_Remove_Programs AS arp INNER JOIN
                           dbo.v_R_System ON arp.ResourceID = dbo.v_R_System.ResourceID INNER JOIN
                           dbo.v_RA_System_SMSInstalledSites AS ASSG ON dbo.v_R_System.ResourceID = ASSG.ResourceID INNER JOIN
                           dbo.v_GS_OPERATING_SYSTEM ON dbo.v_R_System.ResourceID = dbo.v_GS_OPERATING_SYSTEM.ResourceID,
    [dbo].[v_ClientMachines] Dev
     WHERE     (arp.DisplayName0 LIKE '%Microsoft Office%edition%' OR
                           arp.DisplayName0 LIKE '%Microsoft Office Standard 2007%' OR
                           arp.DisplayName0 LIKE '%Microsoft Office Enterprise 2007%' OR
                           arp.DisplayName0 LIKE '%Microsoft Office Professional%2007%' OR
                           arp.DisplayName0 LIKE '%Microsoft Office Standard 2010%' OR
                           arp.DisplayName0 LIKE '%Microsoft Office Enterprise 2010%' OR
                           arp.DisplayName0 LIKE '%Microsoft Office Professional%2010%' OR
                           arp.DisplayName0 LIKE 'Microsoft Office 2000%' OR
                           arp.DisplayName0 LIKE '%Microsoft Office Standard 2013%' OR
             arp.DisplayName0 LIKE '%Microsoft Office Professional 2013%' OR
           arp.DisplayName0 LIKE '%Microsoft Office Enterprise 2013%' OR
                           arp.DisplayName0 LIKE 'Microsoft Office XP%') AND (arp.DisplayName0 NOT LIKE '%update%') AND
                           (arp.DisplayName0 NOT LIKE '%Microsoft Office XP Web Components') AND (dbo.v_R_System.Operating_System_Name_and0 NOT LIKE '%server%')
    AND
                          (arp.InstallDate0 NOT LIKE 'NULL')AND  dbo.v_R_System.Name0 like 'SYstem Name%'
     ORDER BY dbo.v_GS_OPERATING_SYSTEM.Caption0, arp.DisplayName0, arp.Version0
    , Dev.sitecode
    Issue-> Out put value is repeating.

    Query Result--
    S/No   Name         O/S
                           O/S Service Pack      Display Name       Version    Site Code                   
    1    DDSTCCC123   Microsoft Windows 7 Prof    Service Pack 1     Oracle Data Provider   10.1.030    DDS
    2    DDSTCCC123   Microsoft Windows 7 Prof    Service Pack 1     Oracle Data Provider   10.1.030    DDS
    3    DDSTCCC123   Microsoft Windows 7 Prof    Service Pack 1     Oracle Data Provider   10.1.030    DDS
    4    DDSTCCC123   Microsoft Windows 7 Prof    Service Pack 1     Oracle Data Provider   10.1.030    DDS
    Each entry is repeating so many times after using DISTINCT.
     

  • How to query in SCCM 2012 to know how many active and inactive clients in a specific time and date

    Dear Everyone,
    Good morning. I need to perform a query to know how many clients PCs are active or inactive during the a specific time and date (let say, today 9pm). In my query, I want to know:
    1. How many client PCs is active at that time and date?
    2. How many client PCs is not inactive at that time and date?
    Any assistance is greatly appreciated. Thanks.

    Thank you Gerry for pointing out that it doesn't show real time date. I do agree with that. However, I am look at the (at least in this) report which supposed to [description] shows a list of computers not reporting any power activity for a specified date
    and time. Since I can only key in date in my selection (time option not given), I am expecting the report to show me whether there any client PCs that doesn't any power activity for the specified date. A list was generated, and a number of them shows HardwareInventoryScan,
    LastHeartBeatScan and LastPolicyRequest on the same date itself. I would like to know why these appears, so that I can learn from it.
    Due to the selection option given, I can't expect my original goal, but at least (hopefully) I can get to know (past event) how many and which client PCs is not powered on a particular date based on the date and collection selected.
    At least by getting explainations, I hope to learn something from this (how to read this report). Thanks in advance.

  • Create Report based on Query in SCCM 2012

    I have a lot of useful queries, however I would like to create a few reports based on these queries. What is the simple way to do this? I started to create a New Report, but kind of lost after that. Is there a way I can just copy my statement from the
    query to a blank report?

    Execute the WQL query from the queries node in the console and watch smsprov.log on the site server. It should contain the "translated" SQL statement.
    Torsten Meringer | http://www.mssccmfaq.de

  • Create a system properties Query in SCCM 2012 r2

    Hi,
    I am trying to create a query to find the "Computer description" field information for devices, but i am not sure of what criteria if any to select. 
    I was able to successfully create a query statement that finds the description information for a device, but that pulls only the AD object field information and not the local device information as described above.

    Is this the one?
    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_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_OPERATING_SYSTEM.Description != 'Staff Device'

  • SCCM 2012 Query to find units with IPv6 Enabled?

    We've found a need to locate computers that may have IPv6 enabled for audit purposes, and then we'll disable them at a later date.
    Has anyone been able to create a successful query in SCCM 2012 to get that information? 
    I found this but it spit back the IPv4 info for all the units in our device collection, plus it's for SCCM 2007. http://www.myitforum.com/forums/Query-for-systems-with-IPv6-enabled-m227020.aspx
    Appreciate any input, thanks!
    This topic first appeared in the Spiceworks Community

    If you're using % in the value field the operator must be "Like" . In your case, the query should look like
    select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.UserPrincipalName Like
    "TQA%" order by SMS_R_User.UserPrincipalName
    Kindly mark as answer/Vote as helpful if a reply from anybody helped you in this forum. Delphin

  • MOF file migration from SCCM 2007 to SCCM 2012

    Hi,
    I have an issue while migrating SCCM 2007 MOF (Configuration.mof) to SCCM 2012,Problem is...
    In our infrastructure, We have integrated our custom inventory classes with the logon script.Now we are migrating to SCCM 2012.When i migrate the same Custom inventory classes to SCCM 2012,I can able to compile/migrate, However SCCM 2012 views are not in
    sync with SCCM 2007.
    Example: If i use SCCM 2007 collection/Query in SCCM 2012 that uses these custom inventory classes, its thrown an error saying that objects in this query are not valid, because of this none of the collections/Queries that uses old inventory classes are not
    working.
    I dont want to change anything in the logon script...
    Can someone please help me on this.Thanks in advance..
    srkr

    Hi Garth,
    Thanks for the reply.
    As per my understand,there's nothing to do with SMS_DEF.mof and only Configuration.mof can be editable.
    When you say Importing sms_def.mof in SCCM 2012,I guess there's is something i missed out.
    Below is the both SMS_DEF.mof and Configuration.mof from SCCM 2007, Also please let me know how to import SMS_DEF.mof in SCCM 2012
    ************SMS_DEF.MOF*********************
    //-- SCCM Report: XXX_AD_Info
    [SMS_Report(TRUE), 
    SMS_Group_Name("XXX AD Info"), 
    ResID(6200), 
    ResDLL("SMS_RXPL.dll"), 
    SMS_Class_ID("XXX|EDADInfo|5.0")]
    class XXX_AD_Info
    [SMS_Report(TRUE), key]
    string          KeyName;
    [SMS_Report(TRUE)]
    string          Distinguished_Name;
    [SMS_Report(TRUE)]
    string          AD_Site;
    [SMS_Report(TRUE)]
    string          DCName;
    [SMS_Report(TRUE)]
    string          MachineDomain;
    *********Configuration.mof*******************
    //--SCCM Instance: XXX_AD_Info
    [DYNPROPS]
    class XXX_AD_Info
    [key]
    string          KeyName;
    string          Distinguished_Name;
    string          AD_Site;
    string          DCName;
    string          MachineDomain;
    //--SCCM Instance: XXX_AD_Info
    [DYNPROPS]
    instance of XXX_AD_Info
    KeyName = "XXX AD Info";
            [PropertyContext("local|HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\State\\Machine|Distinguished-Name"), Dynamic, Provider("RegPropProv")]
    Distinguished_Name;
            [PropertyContext("local|HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\State\\Machine|Site-Name"), Dynamic, Provider("RegPropProv")]
    AD_Site;
            [PropertyContext("local|HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History|DCName"), Dynamic, Provider("RegPropProv")]
    DCName;
            [PropertyContext("local|HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History|MachineDomain"), Dynamic, Provider("RegPropProv")]
    MachineDomain;
    srkr

  • SCCM 2012 report with BitLocker status

    I am not an expert in SCCM 2012 Report Builder and i am trying to create a report with>
    computername(laptop),drive letter, bitlocker status
    I can't find the property to use in report builder to read the drive letter and bitlocker status. Is there someone who can help me out or had a rdl report file for me ?
    PS. creating a query in SCCM 2012 is easy and works...but how to create a report out of it ??

    SELECT dbo.v_R_System.Name0, dbo.v_GS_ENCRYPTABLE_VOLUME.DriveLetter0, dbo.v_GS_ENCRYPTABLE_VOLUME.ProtectionStatus0
    FROM dbo.v_GS_ENCRYPTABLE_VOLUME INNER JOIN
    dbo.v_R_System ON dbo.v_GS_ENCRYPTABLE_VOLUME.ResourceID = dbo.v_R_System.ResourceID
    Please use the query above, you need to create your own data source of this Report. For more information, please ask at SQL forum, there is a dedicated SSRS forum for this kind of question.
    Juke Chou
    TechNet Community Support

  • SCCM 2012 report for all versions on MS lync installed

    Hello,
    I have installed Microsoft Lync 2010 and Lync 2013 on computers in my company and I have different versions
    like 32 and 64 bits, 365 etc I want to make query in SCCM 2012 to tell me the total number of Microsoft Lync clients Installed on win 8 machines in my company, is there a best way to do this I need your advice..
    I have tried various built in reports and not been successful so far.
    Thanks in Advance

    There's a thread already explaining this :
    http://social.technet.microsoft.com/Forums/en-US/f16f1ee8-206c-42a1-af0e-0363c51b840c/how-to-know-total-of-microsoft-lync-installed-on-computers-in-sccm-2012?forum=configmanagergeneral
    Benoit Lecours | Blog: System Center Dudes

  • SCCM 2012 SQL Server Report Builder Error

    I am trying to create a report with SQL query on SCCM 2012. I get the below error.
    TITLE: Microsoft SQL Server Report Builder
    An error occurred while executing the query.
    The SELECT permission was denied on the object 'v_GS_OPERATING_SYSTEM', database 'CM_C01', schema 'dbo'.
    ADDITIONAL INFORMATION:
    The SELECT permission was denied on the object 'v_GS_OPERATING_SYSTEM', database 'CM_C01', schema 'dbo'. (Microsoft SQL Server, Error: 229)
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=11.00.3000&EvtSrc=MSSQLServer&EvtID=229&LinkId=20476
    BUTTONS:
    OK

    Does your account have accesses within SQL? Bases on the error message I'm guessing not.
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

  • SCCM 2012 - Export Query Results

    Hi guys, I have a query under "Monitoring" - "Overview" - "Queries" and have my results in the result pane however I want to print the report or export to a CSV file. I cant see an easy way to do this? Surely we dont have to create the query then
    create a report just so we can export or print the report? Information is on my screen and is exactly what I want but no obvious easy way to get this in a format that is usable
    I only see the export MOF option available
    Thanks
    Nick

    I know this is an old post but I see Garth replied a couple days ago - on this same theme I have just upgraded to Office 2013 and the cut and paste from Queries and Collections from SCCM 2012 (which worked fine in Office 2010) seems to now not
    work with my Excel 2013 - you do mention it works for you in your post.  The results I see that I have 4 columns in my results it just pastes them into 1 cell - it doesn't break up the columns.  I have tried pasting to notepad first then to Excel
    - doesn't work - also tried Paste - Special - Unicode Text or Text and still it all goes into one cell. Is there something I have to change with either SCCM or Excel to get this to work again?
    Let me know if you have run into this with Excel 2013....thanks
    Kevin
    I am seeing the same issue.  Win 7/Office 2013 fully patched.
    Edit: Got it to work by pasting into Notepad, saving as .txt and opening that file with Excel.

  • SCCM 2012 R2 Report using WMI Query

    I am trying to find out if I can generate a report to show which users installed what software using a report in SCCM 2012 R2 and a WMI Query.
    If not using the reporting within SCCM, then:
    1)  is it possible to pull such data via a wmi query
    2)  any suggestions how to do so?
    3)  Desktop OS is either Windows 7 or 8 or 8.1 Enterprise x64
    Thanks,
    Dave
    David Lakey

    You Can Create Query With the Software name but you can Know Which Computer and you can add System Resource as the Last login name
    This for Example:-
    From monitoring--> Create New Query--> Edit Query Statement --> Show Query Language
    past the following:- 
    select SMS_R_System.NetbiosName, 
    SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName 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 "%Visio%"
    After that in General you can add in Results Tap:-
    System Source and the Attribute Will be last Login name

Maybe you are looking for