[英]Powershell WQL query (SCCM) how do you filter on two WHERE?
[英]Combine queries (WQL subselect query - Powershell - SCCM)
現在,我正在使用兩個不同的查詢並比較生成的對象,但是我更希望使用一個唯一的查詢來完成所有需要的操作,因為我希望直接在SCCM中使用它,而不僅僅是PowerShell。
(第一個查詢將創建一個對象,其中包含已安裝某些x64軟件的所有計算機,第二個對象將創建一個查詢,其中包含未安裝某些x86軟件的所有計算機)
比較這兩個對象,就可以得到所需的列表(兩個對象中都有哪些機器)
但是,我將如何結合這兩個查詢,使它們全部合而為一?
如:
所有具有SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName =“ SOFTWARE1”並且沒有SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName =“ SOFTWARE2”的計算機
$SiteCode = "x"
$SiteServer = "x"
$query = @"
select * from SMS_R_System
inner join SMS_G_System_ADD_REMOVE_PROGRAMS_64
on SMS_G_System_ADD_REMOVE_PROGRAMS_64.ResourceId = SMS_R_System.ResourceId
where SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName = "SOFTWARE1"
"@
$postes_xx = (Get-WmiObject -namespace root\sms\site_$SiteCode -computer $SiteServer -query $query).SMS_R_SYSTEM.Name
$query = @"
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_COMPUTER_SYSTEM
on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId
where SMS_G_System_COMPUTER_SYSTEM.Name
not in (select distinct SMS_G_System_COMPUTER_SYSTEM.Name
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_ADD_REMOVE_PROGRAMS
on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = "SOFTWARE2" )
"@
$postes_32x = Get-WmiObject -namespace root\sms\site_$SiteCode -computer $SiteServer -query $query | select -ExpandProperty name
Compare-Object $postes_xx $postes_x32 -IncludeEqual -ExcludeDifferent
似乎您可以只包括所有聯接,然后將where語句與and
組合在一起。 您將需要調整select
語句以包含您關心的列。
$query = @"
select * from SMS_R_System
inner join SMS_G_System_ADD_REMOVE_PROGRAMS_64
on SMS_G_System_ADD_REMOVE_PROGRAMS_64.ResourceId = SMS_R_System.ResourceId
inner join SMS_G_System_COMPUTER_SYSTEM
on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId
where (SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName = "SOFTWARE1")
and (SMS_G_System_COMPUTER_SYSTEM.Name
not in (select distinct SMS_G_System_COMPUTER_SYSTEM.Name
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_ADD_REMOVE_PROGRAMS
on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = "SOFTWARE2" ))
"@
似乎沒有必要使用SMS_G_System_Computer_System類。 這是應該滿足您要求的WQL的簡單版本。
select SMS_R_System.Name
from SMS_R_System
where SMS_R_System.ResourceID in
(select SMS_G_System_ADD_REMOVE_PROGRAMS_64.ResourceID
from SMS_G_System_ADD_REMOVE_PROGRAMS_64
where SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName = "SOFTWARE1")
and SMS_R_System.ResourceID not in
(select SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID
from SMS_G_System_ADD_REMOVE_PROGRAMS
where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = "SOFTWARE2")
希望我的回答能對您有所幫助,並期待您的反饋。
最好的問候,雷
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.