是否可以通过PowerShell设置IIS SMTP高级日志记录选项卡



在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()
#
}

解决这个问题的关键是查看使用$SMTPConfig返回的所有属性。这显示了所有要设置为True的扩展日志记录属性。$SmtpConfig=获取WMIObject-命名空间根/MicrosoftIISv2-计算机名localhost-查询"选择"*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()
}

最新更新