Powershell

SCCM PowerShell - 針對特定設備集合執行 Invoke-CMWmiQuery?

  • June 2, 2019

我有以下 WQL 查詢:

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_EndpointProtectionStatus on SMS_G_System_EndpointProtectionStatus.ResourceID = SMS_R_System.ResourceId where SMS_G_System_EndpointProtectionStatus.SignatureOlderThan7Days = 1

我可以通過使用來執行它

Invoke-CMWmiQuery -Query $WQL -Option Lazy

但是有沒有辦法可以將其限制為針對特定設備集合執行,就像您可以在 SCCM 控制台中那樣?

謝謝!

感謝 u/Johnny_Script,我在Reddit上找到了答案:

為了將結果限制為一個集合,您需要在join SMS_FullCollectionMembership on SMS_FullCollectionMembership.ResourceID = SMS_R_System.ResourceID查詢中添加一個,以便您可以訪問集合數據。然後您需要添加 AND SMS_FullCollectionMembership.CollectionID = 'ABC0001'到查詢的末尾以限製到特定的集合。使用您的 CollectionID 之一的 CollectionID 更新 ABC0001。最終的 WQL 語句應如下所示:

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_EndpointProtectionStatus on SMS_G_System_EndpointProtectionStatus.ResourceID = SMS_R_System.ResourceId JOIN SMS_FullCollectionMembership on SMS_FullCollectionMembership.ResourceID = SMS_R_System.ResourceID 
WHERE SMS_G_System_EndpointProtectionStatus.SignatureOlderThan7Days = 1 and SMS_FullCollectionMembership.CollectionID = 'ABC0001'

您可以創建一個 SCCM 查詢,然後針對設備集合執行它。 https://docs.microsoft.com/en-us/sccm/core/servers/manage/create-queries

引用自:https://serverfault.com/questions/969569