在远程 powershell 会话的过滤器内使用局部变量

问题描述

我针对这个问题搜索了很长时间,并找到了在远程 Power Shell 会话中使用变量的多个链接

Using a local variable in a remote powershell session

Passing local variables to a remote session in PowerShell 3.0

但是我找不到如何将它传递到引用过滤器公式的部分的解决方案...

这是我认为应该起作用的:

Invoke-Command -Session $hex_session {New-AddressList -Name ($args[0] + " - All Rooms") -RecipientFilter ("(CustomAttribute1 -eq '" + $args[0] + "' -and (RecipientdisplayType -eq 'ConferenceRoomMailBox')") -RecipientContainer ("bla.blup.com/Hosted/"+$args[0])} -ArgumentList $Tenant

但是没有...

我在服务器上输入的原始命令是:

New-AddressList -Name "Tenant00001 – All Rooms" -RecipientFilter "(CustomAttribute1 -eq 'Tenant00001') -and (RecipientdisplayType -eq 'ConferenceRoomMailBox')" -RecipientContainer "bla.blup.com/Hosted/Tenant00001"

有人遇到过同样的问题吗?

感谢您的帮助

干杯 伊夫

解决方法

好的……还有一些反复试验。我自己解决了。

解决办法如下:

Invoke-Command -Session $hex_session {New-AddressList -Name ($args[0] + " - All Rooms") -RecipientFilter ("(CustomAttribute1 -eq '$args') -and (RecipientDisplayType -eq 'ConferenceRoomMailbox')") -RecipientContainer ("bli.blup.com/Hosted/"+$args[0])} -ArgumentList $Tenant