【发布时间】:2020-07-13 13:11:43
【问题描述】:
在使用 IIS SMTP 功能创建 SMTP 中继的 Windows Server 2016/2019 中,我需要通过 PowerShell 启用 SMTP 日志记录并启用日志记录属性(高级选项卡)中的所有详细选项。请参阅超链接。 Image of advanced logging
我有配置 IIS SMTP 以利用 SendGrid 并启用日志记录的代码,但不知道如何配置要启用的高级日志记录选项卡的日志记录属性。有谁知道如何做到这一点或是否有可能?
function ConfigureSMTP
{
$SmtpConfig = Get-WMIObject -Namespace root/MicrosoftIISv2 -ComputerName localhost -Query "Select * From IisSmtpServerSetting"
#$RelayIpList = @( 24, 0, 0, 128, 32, 0, 0, 128, 60, 0, 0, 128, 68, 0, 0, 128, 1, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 76, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 127, 0, 0, 1 )
#$SmtpConfig.RelayIPList = $RelayIPList
$SmtpConfig.AuthFlags = "1"
$SmtpConfig.AuthBasic = $false
$SmtpConfig.RouteAction = "268"
$SmtpConfig.RouteUserName = "apikey"
$SmtpConfig.RoutePassword = $apikeypass
Write-Verbose "Sendgrid API Key: $apikeypass"
$SmtpConfig.AlwaysUseSsl = $true
$SmtpConfig.SmartHostType = "2"
$SmtpConfig.DefaultDomain = $smtpfqdn
$SmtpConfig.SmartHost = "smtp.sendgrid.net"
$SmtpConfig.RemoteSmtpPort = "587"
$smtpconfig.RelayIPList = @(24,0,0,128,32,0,0,128,60,0,0,128,68,0,0,128,1,0,0,0,76,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0,76,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255)
$SmtpConfig.Put()
Set-Service "SMTPSVC" -StartupType Automatic -ErrorAction SilentlyContinue
Start-Service "SMTPSVC" -ErrorAction SilentlyContinue
# This flips 1=logging on, 2=logging off
$mySite = [ADSI]"IIS://Localhost/smtpsvc/1"
$mySite.Put("LogType", 1)
$mySite.SetInfo()
#
}
【问题讨论】:
-
嘿,你想明白了吗?我也在找。谢谢!
-
是的,我现在才这样做...不知道为什么我以前没有想到这一点,但我没有编写原始脚本。如果您查看 $SMTPConfig 的结果,它将显示它知道如何设置的所有属性 $SmtpConfig = Get-WMIObject -Namespace root/MicrosoftIISv2 -ComputerName localhost -Query "Select * From IisSmtpServerSetting" 所以我只是复制了整个部分,例如下面(线程让我将其切断,但您将在下面看到一个示例) $SmtpConfig.LogExtFileBytesRecv="True" $SmtpConfig.LogExtFileBytesSent="True" $SmtpConfig.LogExtFileClientIp="True"
-
如果这对您有所帮助,请查看下面的答案。