Get-WmiObject - 在 -filter 中使用 OR 运算符?
Get-WmiObject - Use OR-Operator in -filter?
我必须做一些 powershell 脚本修改,但我无法在我的开发机器上正确测试。
这就是为什么我想知道,如果我可以在我的 Get-WmiObject -filter
操作中使用 OR
-运算符?
目前我们使用
(Get-WmiObject -Class Win32_Product -Filter "Name like 'ApplicationName1 Client%'" ...).Uninstall()
但最近我们将应用程序的名称从 ApplicationName1
重命名为 NewName
。这就是为什么我想添加这样的另一个条件:
(Get-WmiObject -Class Win32_Product -Filter "Name like 'ApplicationName1 Client%' OR Name like 'NewName Client%'" ...).Uninstall()
我的问题是:
这是过滤器的有效语法还是会抛出异常/给出错误?如果报错,你会怎么做?
是的,这是有效的语法
例如
Get-WmiObject -Class win32_product -filter "Name Like 'citrix%' OR name like 'Microsoft%'"
将提供所有以 Citrix 开头的产品以及所有以 Microsoft 开头的产品
我必须做一些 powershell 脚本修改,但我无法在我的开发机器上正确测试。
这就是为什么我想知道,如果我可以在我的 Get-WmiObject -filter
操作中使用 OR
-运算符?
目前我们使用
(Get-WmiObject -Class Win32_Product -Filter "Name like 'ApplicationName1 Client%'" ...).Uninstall()
但最近我们将应用程序的名称从 ApplicationName1
重命名为 NewName
。这就是为什么我想添加这样的另一个条件:
(Get-WmiObject -Class Win32_Product -Filter "Name like 'ApplicationName1 Client%' OR Name like 'NewName Client%'" ...).Uninstall()
我的问题是:
这是过滤器的有效语法还是会抛出异常/给出错误?如果报错,你会怎么做?
是的,这是有效的语法
例如
Get-WmiObject -Class win32_product -filter "Name Like 'citrix%' OR name like 'Microsoft%'"
将提供所有以 Citrix 开头的产品以及所有以 Microsoft 开头的产品