Можно ли настроить вкладку «Расширенное ведение журнала IIS SMTP» через PowerShell? - PullRequest
0 голосов
/ 13 июля 2020

В Windows Server 2016/2019 с использованием функции IIS SMTP для создания SMTP-реле. Мне нужно включить ведение журнала SMTP и включить все подробные параметры в свойствах ведения журнала (вкладка «Дополнительно») через PowerShell. См. Гиперссылку. Изображение расширенного ведения журнала

У меня есть код для настройки 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()
    #

}

1 Ответ

0 голосов
/ 06 августа 2020

Ключом к решению этой проблемы был просмотр всех свойств, возвращаемых с помощью $ SMTPConfig. Это показало, что для всех расширенных свойств ведения журнала установлено значение True. $ SmtpConfig = Get-WMIObject -Namespace root / MicrosoftIISv2 -ComputerName localhost -Query "Выбрать * из 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()
    }
...