如何为输入字符串中的每个项添加双引号?

时间:2014-09-11 15:44:28

标签: powershell

我正在尝试将字符串连接到一个对象,格式为"test@yahoo.com,abc@gmail.com,123@yahoo.com"。但是,该参数期望字符串中的每个值都被引号括起来,例如""test@yahoo.com","abc@gmail.com","123@yahoo.com""。错误是“属性验证失败”,它期待一个System.String。我该如何解决这个问题?

确切的代码行是......

$existingconfig = get-mailboxjunkemailconfiguration $_.address
$existingconfig.trustedsendersanddomains += $_.approved_senders

其中$_.approved_senders = "test@yahoo.com,abc@gmail.com,123@yahoo.com"

1 个答案:

答案 0 :(得分:1)

使用Get-MailboxJunkEmailConfiguration -Identity BSmith | Get-Memeber表示TrustedSendersAndDomains属性是multiValuedProperty字符串,即数组。您可以尝试将$_.approved_senders的值更改为包含-Split

的数组
$existingconfig = get-mailboxjunkemailconfiguration $_.address
$existingconfig.trustedsendersanddomains += ($_.approved_senders -Split ",")
相关问题