【问题标题】:Is it possible to set the IIS SMTP Advanced Logging tab via PowerShell?是否可以通过 PowerShell 设置 IIS SMTP 高级日志记录选项卡?
【发布时间】: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"
  • 如果这对您有所帮助,请查看下面的答案。

标签: logging smtp sendgrid


【解决方案1】:

解决这个问题的关键是查看使用 $SMTPConfig 返回的所有属性。这显示所有扩展日志记录属性都设置为 True。 $SmtpConfig = Get-WMIObject -Namespace root/MicrosoftIISv2 -ComputerName localhost -Query "Select * From IisSmtpServerSetting"

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.MaxMessageSize =16777216
    $SmtpConfig.MaxSessionSize=16777216
    $SmtpConfig.LogExtFileBytesRecv="True"
    $SmtpConfig.LogExtFileBytesSent="True"
    $SmtpConfig.LogExtFileClientIp="True"
    $SmtpConfig.LogExtFileComputerName="True"
    $SmtpConfig.LogExtFileCookie="True"
    $SmtpConfig.LogExtFileDate="True"
    $SmtpConfig.LogExtFileHost="True"
    $SmtpConfig.LogExtFileHttpStatus="True"
    $SmtpConfig.LogExtFileHttpSubStatus="True"
    $SmtpConfig.LogExtFileMethod="True"
    $SmtpConfig.LogExtFileProtocolVersion="True"
    $SmtpConfig.LogExtFileReferer="True"
    $SmtpConfig.LogExtFileServerIp="True"
    $SmtpConfig.LogExtFileServerPort="True"
    $SmtpConfig.LogExtFileSiteName="True"
    $SmtpConfig.LogExtFileTime="True"
    $SmtpConfig.LogExtFileTimeTaken="True"
    $SmtpConfig.LogExtFileUriQuery="True"
    $SmtpConfig.LogExtFileUriStem="True"
    $SmtpConfig.LogExtFileUserAgent="True"
    $SmtpConfig.LogExtFileUserName="True"
    $SmtpConfig.LogExtFileWin32Status="True"
    $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()
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 2012-06-06
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    相关资源
    最近更新 更多