【发布时间】:2020-09-23 05:33:03
【问题描述】:
这不是我想要完成的确切场景,但却是我陷入困境的一个很好的例子。
$Path = "\\192.168.1.1\config"
Get-CimInstance -Namespace ROOT\CIMV2 -ClassName Win32_MappedLogicalDisk -Filter "ProviderName=$Path"
当它试图在查询中使用\\ 时,这会产生“无效查询”错误
我知道我可以通过以下方式手动执行此操作:
Get-CimInstance -Namespace ROOT\CIMV2 -ClassName Win32_MappedLogicalDisk -Filter "ProviderName='`\\`\\192.168.1.1`\\config'"
这并不能解决我的问题,因为我需要从变量中传递值
任何帮助将不胜感激
【问题讨论】:
-
我也不想查询整个班级然后进行过滤。例如
Get-CimInstance -Namespace ROOT\CIMV2 -ClassName Win32_MappedLogicalDisk | where {$_.ProviderName -eq $Path}因为它会大大减慢脚本速度
标签: powershell wmi