我想知道如何使用 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"
我想知道如何使用 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"
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:
Get-WmiObject
: $queryNameVersion = "Select Name, Version from Win32_Bios"
Get-WmiObject -Query $queryNameVersion
Get-CimInstance
: $queryNameVersion = "Select Name, Version from Win32_Bios"
Get-CimInstance -Query $queryNameVersion
[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