简体   繁体   English

Powershell花括号和变量未解析

[英]Powershell curly braces and variables not being parsed

I'm trying to bulk update a large amount of distribution lists using powershell, I've written this so far: 我正在尝试使用powershell批量更新大量通讯组列表,到目前为止,我已经编写了以下代码:

foreach ($Item in @(Import-Csv -Path "ranks.csv")) {
$Rank = $Item.Rank
Set-DynamicDistributionGroup -Identity "$Rank" -DisplayName "$Rank (NC)" -Name "$Rank (NC)" -RecipientFilter {(RecipientType -eq "UserMailbox") -and (Title -eq "$Rank") -and (Company -eq "Company")}
}

The Exchange command is correct and all works fine except for the (Title -eq "$Rank") part which doesn't parse the variable and just sends it like this: Exchange命令是正确的,并且除了(Title -eq“ $ Rank”)部分不会解析变量而只是像这样发送变量外,其他命令都可以正常工作:

(RecipientType -eq 'UserMailbox') -and (Title -eq '$Rank') -and (Company -eq 'Company')

I'm guessing it's something to do with the filter for RecipientFilter being inside curly braces but have no idea how to stop this from happening. 我猜想这与RecipientFilter的过滤器在花括号内有关,但不知道如何阻止这种情况的发生。

Any help would be much appreciated as I don't want to have to manually update a few hundred lists! 任何帮助将不胜感激,因为我不想手动更新几百个列表!

Does it work if you create the filter scriptblock using an expandable string? 如果使用可扩展字符串创建过滤器脚本块,是否可以正常工作?

foreach ($Item in @(Import-Csv -Path "ranks.csv")) {
$Rank = $Item.Rank
$filter = [scriptblock]::create("(RecipientType -eq 'UserMailbox') -and (Title -eq '$Rank') -and (Company -eq 'Company')")
Set-DynamicDistributionGroup -Identity "$Rank" -DisplayName "$Rank (NC)" -Name "$Rank (NC)" -RecipientFilter $filter
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM