我正在使用这个 powershell 脚本来处理交换邮箱,其中一个参数(在我必须运行的许多命令中)需要在 RecipientFilter 下嵌入一个变量。无论我做什么类型的扩展,它总是按字面意思(作为$前缀)评估它,而不是扩展它。我不确定是否有一种特殊的方式我应该逃避它,或者什么。想法?
$prefix="FAKEDOM"
New-AddressList -name "AL_${prefix}_Contacts" -RecipientFilter {(RecipientType -eq 'MailContact') -and (CustomAttribute15 -eq $prefix)}
编辑:固定变量名称。请注意,问题是关于 $prefix 的第二次使用,第一次使用正常。
编辑:工作解决方案:
New-AddressList -name "AL_${prefix}_Contacts" -RecipientFilter "(RecipientType -eq 'MailContact') -and (CustomAttribute15 -eq `"${prefix}`" )"