Exchange Online Powershell Set-HostedContentFilterPolicy - 找不到接受参数“BlockedSenders”的位置参数

Exchange Online Powershell Set-HostedContentFilterPolicy - 找不到接受参数“BlockedSenders”的位置参数

我有一个自定义 powershell 脚本,它连接到 Exchange Online 并尝试将垃圾邮件地址和域添加到自定义内容过滤策略。该脚本是:

# Blocks Spammers - Email Address & Domains if required
$Spammers = "E:\scripts\Repository\Exchange-Online\Blocked-Email-Address.csv"
$SpamDomains = "E:\scripts\Repository\Exchange-Online\Blocked-Domains.csv"
$SpamPolicy = 'Corp-Custom-BlockList-For-AntiSPAM'
# Block Senders
Import-Csv $Spammers | foreach {Set-HostedContentFilterPolicy -Identity $SpamPolicy –BlockedSenders @{add=$_.SpamEmailAddresses}}
# Block Domains
Import-Csv $SpamDomains | foreach {Set-HostedContentFilterPolicy -Identity $SpamPolicy –BlockedSenderDomains @{add=$_.SpamDomains}}
# End of Script

“ E:\scripts\Repository\Exchange-Online\Blocked-Email-Address.csv ”文件包含:文本

SpamEmailAddresses
[email protected]

当我将其作为 powershell 脚本运行时出现错误:

# Block Domains
Import-Csv E:\scripts\Repository\Exchange-Online\Blocked-Domains.csv | foreach {Set-HostedContentFilterPolicy -Identity My-Policy â€BlockedSenderDomains'.
    + CategoryInfo          : InvalidArgument: (:) [Set-HostedContentFilterPolicy], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Set-HostedContentFilterPolicy
    + PSComputerName        : outlook.office365.com

但是,当我手动在 powershell 会话中运行命令时,它会成功

请帮忙解决

答案1

相关内容