Powershell

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

  • April 27, 2020

我有一個連接到 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
123@345.com

當我將其作為 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/

引用自:https://serverfault.com/questions/1014214