1. Создаем .bat файл с содержанием:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile «C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1″ -command c:\test.ps1
2. Создаем c:\Welcome.htm с нужным содержанием
3. Создаем файл test.ps1 c cодержание следующего вида:
$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
$SMTPClient = New-Object Net.Mail.SmtpClient(«ip smtp servera»)
$MBXArray = @(Get-Mailbox -ResultSize Unlimited | ? {($_.WhenCreated -gt (Get-Date).AddSeconds(-$ElapsedTime)) -and ($_.ExchangeUserAccountControl -ne «AccountDisabled»)})
ForEach ($mailbox in $MBXArray ) {
$Message = New-Object System.Net.Mail.MailMessage
$Message.From = «postmaster@test.ru»
$Message.Subject = «Добро пожаловать»
$Message.IsBodyHtml = $True
$strMsgTo = $mailbox.PrimarySMTPAddress
$Message.to.add($strMsgTo)
$Message.Body = get-content c:\Welcome.htm
$SMTPClient.Send($Message)
$Message.Dispose()
}
# update registry here with a fresh time stamp
Set-ItemProperty HKLM:\Software\Innervation\$strScriptName -Name «LastRun» -Value (Get-Date) | Out-Null