自动向所有新用户帐户发送“欢迎”电子邮件

自动向所有新用户帐户发送“欢迎”电子邮件

我在 Windows Server 2008 R2 Enterprise Edition x64 上有一个 Exchange Server 2010 Enterprise Edition。我的问题是;

我正在尝试进行设置http://www.ucblogs.net/blogs/exchange/archive/2010/03/23/Automatically-sending-a-_2700_Welcome_2700_-email-to-all-new-user-accounts.aspx 它不工作。此外,当运行 powershell 脚本时,它给了我以下结果

(New-ReceiveConnector -Name "Internal Relay" -Bindings 0.0.0.0:25 -RemoteIPRanges 127.0.0.1 -AuthMechanism None -Enabled $true -Fqdn "myserver.mydomain.com" -PermissionGroups AnonymousUsers -Server mysever | Add-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "ms-Exch-SMTP-Accept-Any-Recipient")

Identity        User                Deny          Inherited 
  AAAa\bbb   NT AUTHORITY\ANON...   False          False

在上面的命令中,“扩展权限”没有信息。

有什么建议么?

$strScriptName =  $MyInvocation.MyCommand.Name
if (!(Get-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name LastRun -EA SilentlyContinue)){

    # this is the first time the script has run - let's create the registry key and value for future runs
    New-Item -path HKLM:\Software\Innervation -EA SilentlyContinue | Out-Null
    New-Item -path HKLM:\Software\Innervation\$strScriptName | Out-Null
    New-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) -propertyType String | Out-Null
    write-host "Initial configuration completed." -ForegroundColor green

}

# get time stamp from registry so we know when it last ran
$LastRun = Get-Date ((Get-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name LastRun).LastRun)
$ElapsedTime = ((Get-Date) - $lastrun).TotalSeconds

$MBXArray = @(Get-Mailbox  -ResultSize Unlimited | ? {($_.WhenCreated -gt (Get-Date).AddSeconds(-$ElapsedTime)) -and ($_.ExchangeUserAccountControl -ne "AccountDisabled")})


ForEach ($mailbox in $MBXArray ) {
$strMsgTo = $mailbox.PrimarySMTPAddress

$strMsgBody = "Hello, "+$mailbox.DisplayName+", and welcome to the Contoso family! Please keep this email for future use. It contains vital information.
$SMTPClient.Send($strMsgFrom,$strMsgTo,$strMsgTitle,$strMsgBody) 
}
# update registry here with a fresh time stamp
Set-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) | Out-Null

上述 powershell 命令在安装了 Exchange Server 2010 Enterprise Edition 的系统上不起作用。运行后,出现以下错误。

HKLM:\Software\Innervation   registry key not valid.   

如何使此 PowerShell 命令与 Exchange Server 2010 兼容?

干杯,

希望很快能得到您的专业建议。提前致谢。

干杯。

答案1

我正在将此脚本与 Exchange 2010 一起使用,但我不得不做一些小调整。另外,请确保您从其中一个 cas 服务器运行此脚本。首先,更改 PSSnapin 以加载 Exchange 2010 模块。

“   if (-not((Get-PSSnapin) -match "Microsoft.Exchange.Management.PowerShell.E2010")){ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 }   ”
Next, edit the $SMTPClient to match this line- “   $SMTPClient = New-Object Net.Mail.SmtpClient("127.0.0.1")  “

自定义脚本后,运行此部分命令来创建注册表项。

##########################BEGIN####################
$strScriptName = $MyInvocation.MyCommand.Name
if (!(Get-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name LastRun -EA SilentlyContinue)){
    # this is the first time the script has run - let's create the registry key and value for future runs
    New-Item -path HKLM:\Software\Innervation -EA SilentlyContinue | Out-Null
    New-Item -path HKLM:\Software\Innervation\$strScriptName | Out-Null
    New-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) -propertyType String | Out-Null
    write-host "Initial configuration completed." -ForegroundColor green
}
# get time stamp from registry so we know when it last ran
$LastRun = Get-Date ((Get-ItemProperty -path HKLM:\Software\Innervation\$strScriptName -Name LastRun).LastRun)
$ElapsedTime = ((Get-Date) - $lastrun).TotalSeconds
######################END####################################

然后注释掉最后一行以进行测试。

#########################BEGIN###############################
Set-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name "LastRun" -Value (Get-Date) | Out-Null
######################END#######################

创建一个新的用户帐户并测试您的脚本,直到您满意为止。按预期工作后,删除注释。

@Toshana

相关内容