locked
Extend question against Config Manager collection members RRS feed

  • Question

  • Hello!

    Is it possible to include or extend the Query in this code so that it NOT includes collection members that are not active? If possible i would like to do this without SCCM CmdLets.

    $SiteServer = 'sccm-server-01'
    $SiteCode = 'S01'
    $Collection = Get-wmiobject -ComputerName $siteServer -NameSpace "ROOT\SMS\site_$SiteCode" -Class SMS_Collection | where {$_.Name -eq "$SCCMPatchCollectionName"}
    $SMSClients = Get-WmiObject -ComputerName $SiteServer -Namespace  "ROOT\SMS\site_$SiteCode" -Query "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='$($Collection.CollectionID)' order by name" | select -ExpandProperty Name
    $SCCMPatchCollectionName = $SMSClients

    Thanks.

    Wednesday, July 4, 2018 5:17 AM

All replies

  • Try this:

    $query = "SELECT * FROM SMS_FullCollectionMembership WHERE IsActive=True AND CollectionID='$($Collection.CollectionID)'" 
    $SMSClients = Get-WmiObject -Query $query -ComputerName $SiteServer -Namespace  "ROOT\SMS\site_$SiteCode" | select -ExpandProperty Name


    \_(ツ)_/


    • Edited by jrv Wednesday, July 4, 2018 5:32 AM
    Wednesday, July 4, 2018 5:29 AM
  • Here is a cleaner way to code commands with many parameters:

    $splat = @{
        Class = 'SMS_FullCollectionMembership'
        Filter = "IsActive=True AND CollectionID='$($Collection.CollectionID)'"
        Namespace = "ROOT\SMS\site_$SiteCode"
        Computer = $SiteServer
    }
    $SMSClients = Get-WmiObject @splat  | select -ExpandProperty Name
    


    \_(ツ)_/

    Wednesday, July 4, 2018 5:36 AM
  • Thanks but the query doesnt work.

    Works: "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='$($Collection.CollectionID)' order by name"

    Doesnt work: "SELECT * FROM SMS_FullCollectionMembership WHERE IsActive=True AND CollectionID='$($Collection.CollectionID)'" 

    /Rickard

    Wednesday, July 4, 2018 6:21 AM
  • Dump the collection elements and run Get-Member on a collection element.


    \_(ツ)_/

    Wednesday, July 4, 2018 6:30 AM
  • Class SMS_FullCollectionMembership : SMS_BaseClass  
    {  
          String AMTFullVersion; 
          UInt32 AMTStatus; 
          UInt32 ClientCertType; 
          UInt32 ClientType;  
          String ClientVersion;  
          String CollectionID;  
          String DeviceCategory; 
          UInt32 DeviceOwner;  
          String Domain;  
          Boolean IsActive;    <<<<<<<<<<<<<========================== 
          Boolean IsAlwaysInternet;  
          UInt32 IsApproved;  
          Boolean IsAssigned;  
          Boolean IsBlocked;  
          Boolean IsClient;  
          Boolean IsDecommissioned;  
          Boolean IsDirect;  
          Boolean IsInternetEnabled;  
          Boolean IsObsolete;  
          Boolean IsVirtualMachine; 
          String Name;  
          UInt32 Priority; 
          UInt32 ResourceID;  
          UInt32 ResourceType;  
          String SiteCode;  
          String SMSID; 
          Boolean SuppressAutoProvision; 
    }; 

    \_(ツ)_/

    Wednesday, July 4, 2018 6:35 AM
  • Thanks!

    Realised that "IsActive" that is in SMS_FullCollectionMembership is not the one showing in SCCM console.

    /Rickard

    Wednesday, July 4, 2018 7:11 AM
  • The console likely shows the state acquired from the client. 

    You should post in SCCM forum for this kind of issue.


    \_(ツ)_/

    Wednesday, July 4, 2018 7:14 AM
  • I will try that. Thanks.

    /Rickard

    Wednesday, July 4, 2018 8:05 AM