3

我想知道如何使用 powershell 运行 WQL 查询。这是 WQL 查询

Select UAR.User, UAR.Application, UAR.CurrentState from sms_fullcollectionmembership as FCM
INNER JOIN SMS_UserApplicationRequest as UAR ON UAR.User=FCM.SMSID
where FCM.CollectionID="100104"
4

2 回答 2

3

As described in the about_WQL help file, you can either use one of these 2 cmdlets: Get-WmiObject or Get-CimInstance, or you can use the [wmisearcher] type accelerator:

Using Get-WmiObject:

 $queryNameVersion = "Select Name, Version from Win32_Bios"
 Get-WmiObject -Query $queryNameVersion

Using Get-CimInstance:

 $queryNameVersion = "Select Name, Version from Win32_Bios"
 Get-CimInstance -Query $queryNameVersion

Using [wmisearcher]:

 $searcher = [wmisearcher]"Select Name, Version from Win32_Bios"
 $searcher.Get()

Get-WmiObject is designed to work with WMI (Microsofts own CIMv2 server implementation), whereas Get-CimInstance is supposed to work with any CIMv2 compliant server (although, AFAIK, WQL is specific to WMI).


In your example, you could put the query into a here-string to maintain readability:

$SCCMQuery = @'
Select UAR.User, UAR.Application, UAR.CurrentState from sms_fullcollectionmembership as FCM
INNER JOIN SMS_UserApplicationRequest as UAR ON UAR.User=FCM.SMSID
where FCM.CollectionID="100104"
'@
$Results = Get-WmiObject -Namespace "root\SMS\Site_Name" -Query $SCCMQuery
于 2015-07-09T07:37:33.900 回答
2
于 2015-07-09T07:37:12.857 回答