WMI/WQL查询Powershell中的双反斜杠 [英] double backslash in WMI/WQL query powershell

查看:143
本文介绍了WMI/WQL查询Powershell中的双反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WQL查询面临着奇怪的问题.

I am facing weird issue with my WQL query.

$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="a\100104"
'@
$Results = Get-WmiObject -Namespace "root\SMS\Site_Name" -Query $SCCMQuery

上面的查询无法正常工作,但是当我在FCM.CollectionID中像这样(a\\100104)添加另一个反斜杠时,它将开始工作.

Above query is not working properly but when i add another backslash in FCM.CollectionID like this(a\\100104) then it start working.

有人可以告诉我为什么它会这样工作吗?我无法在所有值中手动添加反斜杠,因为它们稍后会从其他WMI查询中生成.

Can somebody please advise me why it is working like this? I can't manually put the backslash in all the values as they will later be generated from other WMI query.

推荐答案

如果您查看

WQL使用反斜杠()作为转义符 特点.这与Windows不同 PowerShell,使用反引号 字符(`).

WQL uses the backslash () as its escape character. This is different from Windows PowerShell, which uses the backtick character (`).

在生成的查询中,您可以根据需要通过简单的替换人为地添加斜杠.

In your generated queries you can just artificially add the slash with a simple replace if you wanted.

$SCCMQuery.replace("\","\\")

我确信$SCCMQuery只是一个测试示例,但是查询必须放在代码中的某个地方.

I am sure that $SCCMQuery was just a testing example but the query has to be placed in the code somewhere.

这篇关于WMI/WQL查询Powershell中的双反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆