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

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (10)

现在我正在使用两个不同的查询并比较生成的对象,但是我更喜欢一个独特的查询来完成所有需要的工作,因为我希望直接在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
提问于
用户回答回答于

似乎没有必要使用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")

希望我的回答可以帮助您,并期待您的反馈。

最诚挚的问候,Ray

用户回答回答于

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

"@

扫码关注云+社区

领取腾讯云代金券