首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >组合查询(WQL子选择查询- Powershell - SCCM)

组合查询(WQL子选择查询- Powershell - SCCM)
EN

Stack Overflow用户
提问于 2019-06-06 02:50:39
回答 2查看 1.6K关注 0票数 0

现在我正在使用两个不同的查询并比较结果对象,但是我更喜欢一个唯一的查询来完成所有需要的查询,因为我希望直接在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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-06 10:15:14

似乎不需要使用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")

希望我的回答能对你有所帮助,并期待你的反馈。

致以最好的问候,雷

票数 1
EN

Stack Overflow用户

发布于 2019-06-06 06:31:35

看起来您可以只包含所有的连接,然后将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" ))

"@
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56466389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档