我有一个连接到 Exchange Online 的自定义 powershell 脚本,并尝试将垃圾邮件地址和域添加到自定义内容过滤策略。脚本是:
# 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 会话中手动运行命令时,它会成功
请帮忙解决
很高兴知道此问题已解决,您可以将回复标记为答案。一些类似的脚本: https ://community.spiceworks.com/scripts/show/4424-o365-add-sender-or-domain-to-spam-allow-list http://exchangetips.us/2017/12/add -blocked-senders-to-exchange-online-using-powershell/