繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM