Powershell 为什么Get-MobileDevice不返回基于此筛选器的设备?

Powershell 为什么Get-MobileDevice不返回基于此筛选器的设备?,powershell,exchange-server,exchange-server-2019,Powershell,Exchange Server,Exchange Server 2019,我正在尝试查询Exchange 2019以返回基于用户名的设备,但我使用的筛选器没有返回我期望的结果 例如,我的移动设备记录包含一个UserDisplayName,如下所示 UserDisplayName : Our.domain/Domain Sites/Corp/Todd D. Welch 当我运行bellow命令时,它会像我预期的那样返回我的记录以及其他名为Todd的人 Get-MobileDevice -filter {UserDisplayName -like '*t

我正在尝试查询Exchange 2019以返回基于用户名的设备,但我使用的筛选器没有返回我期望的结果

例如,我的移动设备记录包含一个UserDisplayName,如下所示

UserDisplayName         : Our.domain/Domain Sites/Corp/Todd D. Welch
当我运行bellow命令时,它会像我预期的那样返回我的记录以及其他名为Todd的人

Get-MobileDevice -filter {UserDisplayName -like '*todd*'}
但当我运行这个更具体的查询时,它不会返回任何结果

Get-MobileDevice -filter {UserDisplayName -like '*todd*welch*'}

在我看来,上面的命令应该只返回我的设备信息,我不明白为什么不返回。非常感谢您的帮助。

也许您可以将您的标准链接起来,因为
Get MobileDevice
说明:

可以使用逻辑运算符and和or将多个搜索条件链接在一起。例如,{)-and}或{(-and)-or}

所以你可以试试:

$str = "Our.domain/Domain Sites/Corp/Todd D. Welch"

($str -like '*todd*') -and ( $str -like '*welch*') 
在中返回
True


希望有帮助

我从未发现OPath过滤有多大的灵活性。我认为问题在于在哪里使用星号/通配符。看起来您只能用一个通配符开始和/或结束搜索字符串。别的什么都找不到。我敢打赌,即使是
-filter{UserDisplayName-like'*tod**}
也会失败。我希望我有一个更好的答案。您可能必须执行已经有效的操作,然后使用
Where Object
进行进一步过滤,这是没有人愿意听到的。即使使用Where对象,通配符似乎也无法按预期工作。这找不到任何东西:Get-MobileDevice | Where对象{$$\ UserDisplayName-like“*todd welch*”}这会在UserDisplayName中查找所有带有todd的记录,就像上面的-filter所做的Get-MobileDevice | Where对象{$\ UserDisplayName-like“todd”}这段代码确实有效,但这是一个令人费解和浪费处理资源的代码。Get-MobileDevice-Filter{UserDisplayName-Like“todd”}Where对象{$\ UserDisplayName-Like“welch”}实际上,将两者结合使用要比单独使用
Where对象
更好。在
Where Object
对其进行处理之前,需要完全处理通过管道传输到
Where Object
的任何计算和操作<代码>其中对象总是比
-过滤器
慢。您需要类似于
-filter{UserDisplayName-like'*todd*'}的东西,其中对象{$\ UserDisplayName-like'*welch*“}
。我运行了这个命令,它只找到了具有正确名字和姓氏的记录。谢谢Moerwald!getmobiledevice-Filter{(UserDisplayName-Like“Todd”)-和(UserDisplayName-Like“Welch”)}注意:注释系统正在编辑每个名称前后的*。